我正在尝试编译一个使用OpenVDB的项目。 OpenVDB本身依赖Boost。
该项目包含几个库和几个可执行文件。其中一个库需要OpenVDB(因此需要Boost),而可执行文件则需要该库。
我的CMakeLists可以简化为
根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()
库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})
最后是可执行文件
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)
我知道Boost :: system已被重新设计,我故意这样做以尝试使其链接,但没有成功。
调用的链接器行如下
/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
如您所见,OpenVDB在近端被链接,而boost在被链接之前,因此Im出现了Boost链接错误
/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()'
我不确定为什么要在OpenVDB之前链接Boost,因为我明确指定要在OpenVDB之后链接Boost,并试图强制将它链接到可执行文件的第一个和最后一个。
此错误仅在Linux中发生。
有什么想法吗?