CMake boost linkage not respecting order

278 Views Asked by At

Im trying to compile a project which uses OpenVDB. OpenVDB itself depends on Boost.

The project consists on several libraries and several executables. One of the libraries needs OpenVDB (and therefore, Boost), and the executable needs that library.

My CMakeLists can be simplified as

Root CMakeLists

set(BOOST_LIBRARYDIR ${EXTERNAL_DIR}/boost/stage/lib)
set(BOOST_INCLUDEDIR ${EXTERNAL_DIR}/boost)
set(Boost_NO_SYSTEM_PATHS ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
if (UNIX AND NOT APPLE)
set(Boost_USE_STATIC_RUNTIME ON)
endif()
if (WIN32)
find_package(Boost REQUIRED COMPONENTS filesystem system)
else()
find_package(Boost REQUIRED COMPONENTS system filesystem iostreams)
endif()

Library CMakeLists

find_package(OpenVDB REQUIRED)
find_package(IlmBase REQUIRED)
find_package(TBB REQUIRED)
find_package(zlib REQUIRED)
find_package(CUDA REQUIRED)


add_library(lib STATIC ${SOURCES})

target_link_libraries(lib PUBLIC deCore)
target_link_libraries(lib PUBLIC deGeom)

target_include_directories(lib PUBLIC ${CUDA_TOOLKIT_INCLUDE})
target_include_directories(lib PUBLIC ${CUDA_INCLUDE_DIRS})
target_link_libraries(lib PUBLIC ${CUDA_LIBRARIES})
target_link_libraries(lib PUBLIC ${CUDA_CUBLAS_LIBRARIES})

target_link_libraries(lib
    PUBLIC
    ${OPENVDB_LIBRARIES}
    ${ZLIB_LIBRARIES}
    ${TBB_LIBRARIES}
    ${ILMBASE_LIBRARIES}
    Boost::boost
    )

target_include_directories(lib PUBLIC ${OPENVDB_INCLUDE_DIRS})
target_include_directories(lib PUBLIC ${ILMBASE_INCLUDE_DIRS})
target_include_directories(lib PUBLIC ${TBB_INCLUDE_DIRS})
target_include_directories(lib PUBLIC ${ZLIB_INCLUDE_DIRS})

And finally executable

find_package(GLEW REQUIRED)
find_package(RapidJSON)

add_executable(exe ${SOURCES})

target_include_directories(exe PUBLIC ${RAPIDJSON_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS})

target_include_directories(exe INTERFACE ../../External ../../External/include)
target_link_libraries(exe PUBLIC Boost::system lib ${RAPIDJSON_LIBRARIES} ${GLEW_LIBRARIES} Boost::system)

I know Boost::system is repeteaded, I do it on purpose to try to make it link, without success.

The linker line invoked is the following

/usr/bin/c++   -fopenmp -g -DDEBUG   CMakeFiles/exe.dir/main.cpp.o  -o ../../bin/deStart  -L/opt/cuda/lib64/stubs  -L/opt/cuda/lib64  -L/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1 -Wl,-rpath,/opt/cuda/lib64:/home/jjcasmar/Doctorado/Desilico/External/usr/local/lib: ../../../../External/boost/stage/lib/libboost_system-mt-sd.a ../../lib/liblib.a ../../../../External/lib/Debug/libglew_debug.a ../../../../External/boost/stage/lib/libboost_system-mt-sd.a ../../../../External/lib/Debug/libglfw3_debug.a /usr/lib/libXrandr.so /usr/lib/libXxf86vm.so /usr/lib/libXcursor.so /usr/lib/libXinerama.so /usr/lib/libXi.so /usr/lib/libSM.so /usr/lib/libICE.so /usr/lib/libX11.so /usr/lib/libXext.so -lpthread /usr/lib/librt.so /usr/lib/libdl.so /opt/cuda/lib64/libcublas.so /opt/cuda/lib64/libcublas_device.a ../../../../External/lib/Debug/libzlib_debug.a ../../../../External/lib/Debug/libIlmBase_debug.a -ldl -lgomp ../../../../External/usr/local/library/librestbed.a ../../lib/libdeGL.a ../../lib/libdeCore.a ../../lib/libdeGeom.a ../../lib/libdeCore.a ../../lib/libdeGeom.a ../../../../External/lib/Debug/libmongocxx-static_debug.a ../../../../External/lib/Debug/libbsoncxx-static_debug.a ../../../../External/lib/Release/libmongoc-static-1.0.a ../../../../External/lib/Debug/libbson-static-1.0_debug.a -lstdc++fs -lssl -lcrypto -lcrypt -lresolv -lz -lrt ../../../../External/usr/local/lib/libOpenMeshTools.so ../../../../External/usr/local/lib/libOpenMeshCored.so ../../../../External/usr/local/lib/libOpenMeshToolsd.so ../../../../External/lib/Debug/libglew_debug.a /usr/lib/libGLX.so /usr/lib/libOpenGL.so /opt/cuda/lib64/libcudart.so ../../../../External/lib/Debug/libOpenVDB_debug.a ../../../../External/lib/Debug/libtbb_debug.a ../../../../External/lib/Debug/libtbbmalloc_proxy_debug.a ../../../../External/lib/Debug/libtbbmalloc_debug.a ../../lib/libdeCuda.a -lcudadevrt -lcudart_static -lrt -lpthread -ldl 

As you can see, OpenVDB is being linked at the nearly end, while boost is being linked before, so Im having a boost linkage error as this one

/usr/bin/ld: ../../../../External/lib/Debug/libOpenVDB_debug.a(Archive.o): in function `openvdb::v4_0_1::io::getErrorString[abi:cxx11](int)':
/home/jjcasmar/Doctorado/Desilico/External/prj/gmake/../../OpenVDB/OpenVDB/openvdb/io/Archive.cc:520: undefined reference to `boost::system::generic_category()'

Im not sure why Boost is being linked before OpenVDB, since I clearly specify to link Boost after OpenVDB and tried to force it linking it the first and the last one of the executable.

This error is only happening in Linux.

Any idea of what is happening?

0

There are 0 best solutions below