CMake link shared library to system version instead own - cmake

I have my own libusb version inside the project's source directory, that I find with:
find_path(LibUsb_INCLUDE_DIR NAMES libusb.h PATHS ${CMAKE_CURRENT_SOURCE_DIR}/LibUsb/Include)
if(NOT LibUsb_INCLUDE_DIR)
message(FATAL_ERROR "LibUsb: include directory not found")
endif()
find_library(LibUsb_LIBRARY NAMES usb-1.0 libusb-1.0 PATHS ${OUTPUT_BIN_DIR})
if(NOT LibUsb_LIBRARY)
message(FATAL_ERROR "LibUsb: library not found")
endif()
add_library(LibUsb SHARED IMPORTED GLOBAL)
set_target_properties(LibUsb PROPERTIES IMPORTED_LOCATION ${LibUsb_LIBRARY})
set_target_properties(LibUsb PROPERTIES IMPORTED_IMPLIB ${LibUsb_LIBRARY})
set_target_properties(LibUsb PROPERTIES IMPORTED_NO_SONAME ON)
set_target_properties(LibUsb PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${LibUsb_INCLUDE_DIR})
message(STATUS "LibUsb: found at ${LibUsb_LIBRARY}")
This run successfully where I get
-- LibUsb: found at /mnt/c/x/Build/Linux-Debug/Output/Bin/libusb-1.0.so
Then I link it with
target_link_libraries(${TARGET_NAME} ... LibUsb)
Where I inspected link.txt that CMake produces for that target:
/usr/bin/g++-4.8 -Wall -Werror -Wextra -Wno-missing-field-initializers -g ... -lusb-1.0
But when inspecting my binary I get
gal#GalA-T480:/mnt/c/x$ readelf -d Build/Linux-Debug/Output/Bin/myexe | grep NEEDED
0x0000000000000001 (NEEDED) Shared library: [libusb-1.0.so.0]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
gal#GalA-T480:/mnt/c/x$ ldd Build/Linux-Debug/Output/Bin/myexe
linux-vdso.so.1 (0x00007fffcd197000)
libusb-1.0.so.0 => /lib/x86_64-linux-gnu/libusb-1.0.so.0 (0x00007f1a49930000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f1a495a0000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f1a49380000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f1a49160000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1a48d60000)
libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 (0x00007f1a48b40000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f1a48790000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1a49c00000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f1a48580000)
gal#GalA-T480:/mnt/c/x$
I don't get why the executable searches for libusb-1.0.so.0 and not libusb-1.0.so. I also don't get why it finds it at system directories and not my own.
Can I utilize RPATH somehow to work it out? Preferably using CMake?

Related

Link errors when using CMake and VCPKG with GoogleTest

As a bit of background, I have a project that I have been developing with Visual Studio and VCPKG manifest mode for some time, it contains one static library project and one unit test project. Everything has been working correctly. I'm now trying to migrate this solution to use CMake, this is my first time using CMake.
With CMake the VCPKG dependencies install correctly, and both the static library and unit tests compile, however it fails on the linking step with a large number of linker errors all related to the GoogleTest library. Here is the first, as an example:
CppSlippiTest.obj : error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl testing::internal::FormatMatcherDescription(bool,char const *,class std::vector<char const*,class std::allocator<char const *> > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > const &)" (?FormatMatcherDescription#internal#testing##YA?AV$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##_NPEBDAEBV?$vector#PEBDV$allocator#PEBD#std###4#AEBV?$vector#V?$basic_string#DU?$char_traits#D#std##V$allocator#D#2##std##V?$allocator#V?$basic_string#DU$char_traits#D#std##V?$allocator#D#2##std###2##4##Z) referenced in function "private: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl cpp_slippi::MatchOptionalMatcherP2<class testing::internal::Eq2Matcher,class std::optional<unsigned char> >::gmock_Impl<class std::optional<unsigned char> const &>::FormatDescription(bool)const " (?FormatDescription#$gmock_Impl#AEBV?$optional#E#std###$MatchOptionalMatcherP2#VEq2Matcher#internal#testing##V?$optional#E#std###cpp_slippi##AEBA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##_N#Z) [C:\Users\Derek\Projects\CppSlippi\build\Test.vcxproj]
There are 36 more of these.
Here is my CMakeLists.txt, slightly abridged for clarity:
cmake_minimum_required(VERSION 3.12...3.24)
# Must be before project()
set(VCPKG_TARGET_TRIPLET x64-windows-static)
project(CppSlippi
VERSION 1.0
DESCRIPTION "Slippi replay file parsing library for C++."
LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(GTest CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
add_library(CppSlippi STATIC
CppSlippi/src/CppSlippi.cpp
CppSlippi/src/CppSlippi.h
...)
target_include_directories(CppSlippi PUBLIC CppSlippi/src)
target_compile_features(CppSlippi PUBLIC cxx_std_20)
target_compile_options(CppSlippi PUBLIC /MTd)
set_target_properties(CppSlippi PROPERTIES CXX_EXTENSIONS OFF)
target_link_libraries(CppSlippi PUBLIC nlohmann_json::nlohmann_json)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
include(GoogleTest)
endif()
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
add_executable(Test
Test/src/CppSlippiTest.cpp
...)
target_include_directories(Test PUBLIC Test/src)
target_compile_features(Test PUBLIC cxx_std_20)
target_compile_options(Test PRIVATE /bigobj /MTd)
set_target_properties(Test PROPERTIES CXX_EXTENSIONS OFF)
target_link_libraries(Test PUBLIC
CppSlippi
nlohmann_json::nlohmann_json
GTest::gtest_main)
gtest_discover_tests(Test)
endif()
Here is my VCPKG manifest:
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
"name": "cpp-slippi",
"version": "1.0.0",
"description": "C++ Slippi replay parser.",
"builtin-baseline": "68b7fec22eb5fd9c0236b1e42b3c0deb8e771b37",
"dependencies": [
"gtest",
"nlohmann-json"
],
"supports": "windows"
}
And to build this I am running:
cmake --build build --target Test
I turned on --verbose to get more information, and this is the link command that CMake is running:
Link:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\HostX64\x64\link.exe /ERRORREPO
RT:QUEUE /OUT:"C:\Users\Derek\Projects\CppSlippi\build\Debug\Test.exe" /INCREMENTAL /ILK:"Test.dir\Debug\Test.ilk" /N
OLOGO /NATVIS:"C:\Users\Derek\Projects\CppSlippi\build\vcpkg_installed\x64-windows-static\share\nlohmann_json\nlohman
n_json.natvis" Debug\CppSlippi.lib "vcpkg_installed\x64-windows-static\debug\lib\manual-link\gtest_main.lib" "vcpkg_i
nstalled\x64-windows-static\debug\lib\gtest.lib" kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib
oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifes
t:embed /DEBUG /PDB:"C:/Users/Derek/Projects/CppSlippi/build/Debug/Test.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE
/NXCOMPAT /IMPLIB:"C:/Users/Derek/Projects/CppSlippi/build/Debug/Test.lib" /MACHINE:X64 /machine:x64 Test.dir\Debug
\CppSlippiTest.obj ...
Note the presence of gtest_main.lib and gtest.lib, these are the libraries that I believe should include the missing functions. I have checked that these files are present at the locations shown.
I know that in Visual Studio using the GoogleTest main requires adding an AdditionalDependency manually, but from all the instructions I can find this should not be necessary in CMake and the .lib is already in the command line. I did try using target_link_directories anyways, but this did not help.
At this point I am baffled and searching on Google and Stack Overflow has failed to turn up any help.
You link only one of 4 GoogleTest libraries to your app
target_link_libraries(Test PUBLIC
CppSlippi
nlohmann_json::nlohmann_json
GTest::gtest_main)
Depending on the application needs, it should be linked to at least one more library
target_link_libraries(Test PUBLIC
CppSlippi
nlohmann_json::nlohmann_json
GTest::gtest_main
GTest::gtest)
Or
target_link_libraries(Test PUBLIC
CppSlippi
nlohmann_json::nlohmann_json
GTest::gmock_main
GTest::gmock
GTest::gtest)

Why No ops registered when I try to load frozen model in Android NDK?

I want to use c++ tensorflow API through ndk and cmake, I can create the library but when I load a frozen model a lot of errors like this when I try to load graph:
E/native: op_kernel.cc:1148 OpKernel ('op: "PopulationCount"
device_type: "CPU" constraint { name: "T" allowed_values { list {
type: DT_INT32 } } }') for unknown op: PopulationCount
So I understand that my library does not support the operations.
Do I need to add another library to support these operations?
I based my Cmake script on this Cmakelist and
I used the build_android_all.sh script to build the dependencies for armeabi-v7a.
This is how my cmake script looks like:
cmake_minimum_required(VERSION 3.4.1)
include(ExternalProject)
SET(PROJECT_NAME tf_native_lib)
SET(OpenCV_FOUND true )
SET(PREBUILT_DIR ${TENSORFLOW_ROOT_DIR}/tensorflow/contrib/makefile/gen)
SET(TARGET_NSYNC_LIB ${TENSORFLOW_ROOT_DIR}/tensorflow/contrib/makefile /downloads/nsync/builds/${ANDROID_ABI}.android.c++11)
FIND_PACKAGE(OpenCV REQUIRED)
add_library( # Sets the name of the library.
${PROJECT_NAME}
SHARED
src/main/cpp/native-lib.h
src/main/cpp/native-lib.cpp
src/main/cpp/TensorflowInferenceHandler.h
src/main/cpp/TensorflowInferenceHandler.cpp
)
add_library(lib_proto STATIC IMPORTED )
set_target_properties(lib_proto PROPERTIES IMPORTED_LOCATION
${PREBUILT_DIR}/protobuf_android/${ANDROID_ABI}/lib/libprotobuf.a)
add_library(lib_nsync STATIC IMPORTED )
set_target_properties(lib_nsync PROPERTIES IMPORTED_LOCATION
${TARGET_NSYNC_LIB}/libnsync.a)
add_library(lib_tf STATIC IMPORTED )
set_target_properties(lib_tf PROPERTIES IMPORTED_LOCATION
${PREBUILT_DIR}/lib/android_${ANDROID_ABI}/libtensorflow-core.a)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIS_SLIM_BUILD \
-std=c++11 -fno-rtti -fno-exceptions \
-O2 -Wno-narrowing -fomit-frame-pointer \
-mfpu=neon -mfloat-abi=softfp -fPIE -fPIC \
-ftemplate-depth=900 \
-DGOOGLE_PROTOBUF_NO_RTTI \
-DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} \
-Wl,--allow-multiple-definition \
-Wl,--whole-archive \
-fPIE -pie -v")
# MESSAGE("tensorflow lib dir ${TENSORFLOW_LIB_DIR}")
target_link_libraries( # Specifies the target library.
${PROJECT_NAME}
${OpenCV_LIBS}
android
dl
log
m
z
jnigraphics
lib_tf
lib_proto
lib_nsync)
include_directories(
${OPENCV_INCLUDE_DIRS}
${PREBUILT_DIR}/proto
${PREBUILT_DIR}/protobuf_android/${ANDROID_ABI}/include
${PREBUILT_DIR}/nsync/public
${TENSORFLOW_ROOT_DIR}/tensorflow/contrib/makefile/downloads/eigen
${TENSORFLOW_ROOT_DIR}/bazel-tensorflow/external/nsync/public
${TENSORFLOW_ROOT_DIR}/bazel-genfiles
${TENSORFLOW_ROOT_DIR}
../../../cpp_utils)
If this is not possible, where are the sources to link the tensorflow_inference.so with my Jni Sources?
Thanks in advance.
Unai.
The PopulationCount and few other Ops are declared in tensorflow/core/ops/bitwise_ops.cc. Add that file to the end of /tensorflow/contrib/makefile/tf_op_files.txt. Then recompile the Tensorflow. That is what worked for me.

undefined reference to `vtable in custom lib created with cmake

I'm getting the error: lib/libhrlLib.so: undefined reference to `hrlQseqDev::waiting(bool, int)' and some more ...
I'm trying to build my project with cmake (3.7.2) instead of with qmake (Qt5)
CMakeLists.txt:
project(${TARGET_NAME})
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 14)
set(POSITION_INDEPENDENT_CODE FALSE)
macro(NAMELIST erg in)
set(os "")
set(srcs ${in})
separate_arguments(srcs)
foreach(is ${srcs})
set(os ${os} ${is})
endforeach(is)
set(${erg} ${os})
endmacro(NAMELIST)
macro(FINDMODULES erg in)
set(os "")
set(srcs ${in})
separate_arguments(srcs)
foreach(is ${srcs})
find_package(Qt5${is} REQUIRED)
set(os ${os} Qt5::${is})
endforeach(is)
set(${erg} ${os})
endmacro(FINDMODULES)
NAMELIST(SRCS ${TARGET_SRCS})
FINDMODULES(QLIBS ${QMODULES})
if(INC_PATH)
NAMELIST(INCS ${INC_PATH})
set(INCLUDES ${INCS})
endif(INC_PATH)
if(TARGET_EXTLIBS)
NAMELIST(EXTRA_LIBS ${EXTRA_LIBS} "${TARGET_EXTLIBS}")
endif(TARGET_EXTLIBS)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
include_directories(${INCLUDES})
if(BUILD_LIB)
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-shared")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-shared")
add_library(${TARGET_NAME} SHARED ${SRCS})
target_link_libraries(${TARGET_NAME} ${QLIBS} ${EXTRA_LIBS})
set_property(TARGET ${TARGET_NAME} PROPERTY VERSION "1.0.0")
set_property(TARGET ${TARGET_NAME} PROPERTY SOVERSION 1 )
install(TARGETS ${TARGET_NAME} LIBRARY DESTINATION lib)
install(TARGETS ${TARGET_NAME} LIBRARY DESTINATION lib NAMELINK_ONLY)
else()
if(USE_LIB_PATH)
add_executable(${TARGET_NAME} ${SRCS})
target_link_libraries(${TARGET_NAME} -L${OUT_PATH}/lib lib${USE_LIB}.so.1
${QLIBS} ${EXTRA_LIBS})
else()
add_executable(${TARGET_NAME} ${SRCS})
target_link_libraries(${TARGET_NAME} ${QLIBS} ${EXTRA_LIBS})
endif(USE_LIB_PATH)
install(TARGETS ${TARGET_NAME} RUNTIME DESTINATION bin)
endif(BUILD_LIB)
The shared library is built with:
cmake -G "Unix Makefiles" -DINC_PATH:STRING="some includes" -DTARGET_EXTLIBS:STRING="sys libs" -DTARGET_NAME:STRING=LibName -DBUILD_LIB:BOOL=1 -DTARGET_SRCS:STRING="cpp- and c-file" -DQMODULES:STRING="Core Gui Widgets PrintSupport" -DOUT_PATH:STRING=InstallPath .. -DCMAKE_INSTALL_PREFIX=InstallPath >> /dev/null
When I try to build a program against this shared library with:
cmake -G "Unix Makefiles" -DINC_PATH:STRING="some includes" -DTARGET_EXTLIBS:STRING="sys libs" -DTARGET_NAME:STRING=ProgName -DBUILD_LIB:BOOL=0 -DTARGET_SRCS:STRING="cpp-file" -DQMODULES:STRING="Core Gui Widgets PrintSupport" -DOUT_PATH=InstallPath -DUSE_LIB:STRING="LibName" -DUSE_LIB_PATH:STRING="BuildPath of LibName" .. -DCMAKE_INSTALL_PREFIX=InstallPath >> /dev/null
I get the error 'lib/libhrlLib.so: undefined reference to ...'.
I do not get this error when the library was built with qmake.
How can I fix this?

References to FFTW not resolved when linking with --as-needed

I have a linking problem which I cannot explain. The program contains references to FFTW functions in a file called fft.cpp. The linking command is as follows (I skipped the rest of object files):
/usr/bin/g++ common/CleanerND.cpp.2.o ... common/fft.cpp.2.o
-o cleaner3d -Wl,-Bstatic -Wl,-Bdynamic -lmkl_intel_lp64 -lmkl_sequential -lmkl_core
-lfftw3f -lgsl -lgslcblas -lm -lglib-2.0 -lz -lm -lpthread -fopenmp
The superfluous -Wl,-Bstatic -Wl,-Bdynamic options are generated by Waf, which I use as the build system. I use the default toolchain that comes with Ubuntu 12.04: GCC 4.6.3, binutils 2.22.
The problem is that the linker does not detect and resolve the references to the FFTW functions. When run, the program aborts with this message:
cleaner3d: symbol lookup error: cleaner3d: undefined symbol: fftwf_malloc
The output ofldd shows that FFTW is not being linked at all:
$ ldd cleaner3d
linux-vdso.so.1 => (0x00007fffa3193000)
libmkl_intel_lp64.so => /opt/intel/mkl/10.0.1.014/lib/em64t/libmkl_intel_lp64.so (0x00007f6f16683000)
libmkl_sequential.so => /opt/intel/mkl/10.0.1.014/lib/em64t/libmkl_sequential.so (0x00007f6f164d3000)
libmkl_core.so => /opt/intel/mkl/10.0.1.014/lib/em64t/libmkl_core.so (0x00007f6f16300000)
libgsl.so.0 => /usr/lib/libgsl.so.0 (0x00007f6f15ec4000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f6f15bcf000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6f158d4000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f6f156b7000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f6f153b7000)
libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f6f151a8000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f6f14f92000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6f14bd5000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6f149d0000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f6f14793000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f6f1458b000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6f169b2000)
This is clearly the linker's fault, since the output of nm shows that it contains references to FFTW:
$ nm build/common/fft.cpp.2.o | grep fftw
U fftwf_destroy_plan
U fftwf_execute_dft
U fftwf_free
U fftwf_malloc
U fftwf_plan_dft_1d
U fftwf_plan_many_dft
I found out that this might be somehow related to the linker option --as-needed, which is passed by default since Ubuntu 12.04 - and indeed, when I add -Wl,--no-as-needed to the command line, the problem disappears. However, this workaround should not be necessary. I don't understand why the linker won't properly link FFTW with --as-needed enabled. Can anyone shine some light on this? Is this a linker bug? Why only the FFTW library is affected?

g++ linking problem

I'm having a weird linking problem and am only beginning programming with c++ so I'm not terribly sure what it means...
main.cpp
#include <iostream>
main(void)
{
return 0;
}
Compiling
esr#athena:~/programming/cpp$ g++ main.cpp
esr#athena:~/programming/cpp$ ./a.out
esr#athena:~/programming/cpp$ g++ main.cpp -L/home/esr/ogre/lib -lOgreMain
esr#athena:~/programming/cpp$ ./a.out
This executes just fine, however, when I link against another of the libraries in the same folder...
esr#athena:~/programming/cpp$ g++ main.cpp -L/home/esr/ogre/lib -lOgreMain -lOgreTerrain
esr#athena:~/programming/cpp$ ./a.out
./a.out: error while loading shared libraries: libOgreTerrain.so.1.7.1: cannot open shared object file: No such file or directory
So what's in that folder?
esr#athena:~/programming/cpp$ ls /home/esr/ogre/lib/
libOgreMain.so Sample_DynTex.so
libOgreMain.so.1.7.1 Sample_FacialAnimation.so
libOgrePaging.so Sample_Fresnel.so
libOgrePaging.so.1.7.1 Sample_Grass.so
libOgreRTShaderSystem.so Sample_Instancing.so
libOgreRTShaderSystem.so.1.7.1 Sample_Isosurf.so
libOgreTerrain.so Sample_Lighting.so
***libOgreTerrain.so.1.7.1*** Sample_Ocean.so
Edit: (the stars are for emphasis, not a file name)
It's right there! Any ideas on what I'm doing wrong?
Edit
Still having problems. Tried linking against all dependencies of libOgreTerrain and that doesn't seem to have satisfied the compiler.
ldd libOgreTerrain.so
linux-vdso.so.1 => (0x00007fff56bff000)
libOgreMain.so.1.7.1 => /home/esr/ogre/lib/libOgreMain.so.1.7.1 (0x00007fd3584c8000)
libOgrePaging.so.1.7.1 => /home/esr/ogre/lib/libOgrePaging.so.1.7.1 (0x00007fd35829b000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x00007fd357fee000)
libSM.so.6 => /usr/lib/libSM.so.6 (0x00007fd357de5000)
libICE.so.6 => /usr/lib/libICE.so.6 (0x00007fd357bca000)
libX11.so.6 => /usr/lib/libX11.so.6 (0x00007fd357893000)
libXext.so.6 => /usr/lib/libXext.so.6 (0x00007fd357681000)
libXt.so.6 => /usr/lib/libXt.so.6 (0x00007fd35741c000)
libXaw.so.7 => /usr/lib/libXaw.so.7 (0x00007fd3571ac000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007fd356f8f000)
libdl.so.2 => /lib/libdl.so.2 (0x00007fd356d8b000)
libfreeimage.so.3 => /usr/lib/libfreeimage.so.3 (0x00007fd3568bc000)
libzzip-0.so.13 => /usr/lib/libzzip-0.so.13 (0x00007fd3566b5000)
libz.so.1 => /lib/libz.so.1 (0x00007fd35649d000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fd356196000)
libm.so.6 => /lib/libm.so.6 (0x00007fd355f13000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007fd355cfd000)
libc.so.6 => /lib/libc.so.6 (0x00007fd355979000)
libuuid.so.1 => /lib/libuuid.so.1 (0x00007fd355774000)
libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007fd355556000)
libXmu.so.6 => /usr/lib/libXmu.so.6 (0x00007fd35533d000)
libXpm.so.4 => /usr/lib/libXpm.so.4 (0x00007fd35512c000)
libXau.so.6 => /usr/lib/libXau.so.6 (0x00007fd354f28000)
libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007fd354d22000)
Changed compilation code to the following:
g++ main.cpp -L/home/esr/ogre/lib -lOgreMain -lOgreTerrain -L/lib -L/usr/lib -lfreetype -lSM -lICE -lX11 -lXext -lXt -lXaw -lpthread -lfreeimage -lxcb -lXmu -lXpm -lXau -lXdmcp -ldl -lzzip -lz -lstdc++ -lm -lgcc_s -lc
Which links against all dependencies as above afaik (uuid wouldn't link).
esr#athena:~/programming/cpp$ g++ main.cpp -L/home/esr/ogre/lib -lOgreMain -lOgreTerrain -L/lib -L/usr/lib -lfreetype -lSM -lICE -lX11 -lXext -lXt -lXaw -lpthread -lfreeimage -lxcb -lXmu -lXpm -lXau -lXdmcp -ldl -lzzip -lz -lstdc++ -lm -lgcc_s -lc
esr#athena:~/programming/cpp$ ./a.out
./a.out: error while loading shared libraries: libOgreTerrain.so.1.7.1: cannot open shared object file: No such file or directory
esr#athena:~/programming/cpp$ LD_LIBRARY_PATH=/home/esr/ogre/lib ./a.out
esr#athena:~/programming/cpp$
Edit 2
Linking of a.out
esr#athena:~/programming/cpp$ ldd a.out
linux-vdso.so.1 => (0x00007fff978a4000)
libOgreMain.so.1.7.1 => /usr/lib/libOgreMain.so.1.7.1 (0x00007f612d528000)
libOgreTerrain.so.1.7.1 => not found
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x00007f612d2a0000)
libSM.so.6 => /usr/lib/libSM.so.6 (0x00007f612d097000)
libICE.so.6 => /usr/lib/libICE.so.6 (0x00007f612ce7c000)
libX11.so.6 => /usr/lib/libX11.so.6 (0x00007f612cb45000)
libXext.so.6 => /usr/lib/libXext.so.6 (0x00007f612c933000)
libXt.so.6 => /usr/lib/libXt.so.6 (0x00007f612c6ce000)
libXaw.so.7 => /usr/lib/libXaw.so.7 (0x00007f612c45e000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007f612c241000)
libfreeimage.so.3 => /usr/lib/libfreeimage.so.3 (0x00007f612bd73000)
libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007f612bb55000)
libXmu.so.6 => /usr/lib/libXmu.so.6 (0x00007f612b93c000)
libXpm.so.4 => /usr/lib/libXpm.so.4 (0x00007f612b72b000)
libXau.so.6 => /usr/lib/libXau.so.6 (0x00007f612b527000)
libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007f612b321000)
libdl.so.2 => /lib/libdl.so.2 (0x00007f612b11d000)
libzzip-0.so.13 => /usr/lib/libzzip-0.so.13 (0x00007f612af15000)
libz.so.1 => /lib/libz.so.1 (0x00007f612acfd000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f612a9f7000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f612a7e0000)
libm.so.6 => /lib/libm.so.6 (0x00007f612a55d000)
libc.so.6 => /lib/libc.so.6 (0x00007f612a1da000)
libuuid.so.1 => /lib/libuuid.so.1 (0x00007f6129fd4000)
/lib64/ld-linux-x86-64.so.2 (0x00007f612dcfc000)
Resolution
Partially resolved thusly, I linked to the shared libraries in the /usr/lib folder, I'm not sure why g++ wouldn't look in there, but it just wouldn't.
Useful links here and here
It's rather simple.
The OS looks for libraries in the directories that exist in the ldconfig.
it seems that libOgreTerrain.so links against some other libraries that were not explicitly specified.
Try this first:
LD_LIBRARY_PATH=/home/esr/ogre/lib ./a.out
You can display dynamic linking paths like that:
ldd ./a.out