我正在尝试使用libcinder进行一些可视化。在我现有的代码库中集成时,我遇到了一些我无法弄清楚的链接器错误。 我把这个问题简化为一个最小的例子,结果如下:
cd /build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/BasicApp.dir/link.txt --verbose=1
/usr/bin/c++ -O3 -DNDEBUG CMakeFiles/BasicApp.dir/BasicApp.cpp.o -o ../bin/BasicApp -rdynamic -lPocoUtil -lPocoFoundation
make[2]: Leaving directory '/build'
[100%] Built target BasicApp
make[1]: Leaving directory '/build'
/usr/bin/cmake -E cmake_progress_start /build/CMakeFiles 0
如果根本不涉及煤渣,一切正常,如上所示。如果我将我的函数添加到最小的cinder示例(BasicApp),我在编译时得到以下输出:
cd /build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/BasicApp.dir/link.txt --verbose=1
/usr/bin/c++ -O3 -DNDEBUG CMakeFiles/BasicApp.dir/BasicApp.cpp.o -o ../bin/BasicApp -rdynamic -lPocoUtil -lPocoFoundation /cinder/lib/linux/x86_64/ogl/Release/libcinder.a -lGLU -lGL -lSM -lICE -lX11 -lXext -lXcursor -lXinerama -lXrandr -lXi -lz -lcurl -lfontconfig -lpulse -lmpg123 -lsndfile -lgobject-2.0 -lglib-2.0 -lgstreamer-1.0 -lgstbase-1.0 -lgstapp-1.0 -lgstvideo-1.0 -lgstgl-1.0 /cinder/lib/linux/x86_64//libboost_system.a /cinder/lib/linux/x86_64//libboost_filesystem.a -ldl -lpthread
CMakeFiles/BasicApp.dir/BasicApp.cpp.o: In function `load_images(std::string, std::string, int, int)':
BasicApp.cpp:(.text+0xca2): undefined reference to `Poco::DirectoryIterator::DirectoryIterator(std::string const&)'
BasicApp.cpp:(.text+0xd57): undefined reference to `Poco::DirectoryIterator::DirectoryIterator(std::string const&)'
collect2: error: ld returned 1 exit status
src/CMakeFiles/BasicApp.dir/build.make:118: recipe for target 'bin/BasicApp' failed
make[2]: *** [bin/BasicApp] Error 1
make[2]: Leaving directory '/build'
CMakeFiles/Makefile2:1244: recipe for target 'src/CMakeFiles/BasicApp.dir/all' failed
make[1]: *** [src/CMakeFiles/BasicApp.dir/all] Error 2
make[1]: Leaving directory '/build'
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
我假设cinder cmake文件中的某些配置设置正在搞乱,但我不明白为什么或如何修复它。 这是使用gcc版本5.4.0和cmake版本3.5.1。
这是一个包含此问题的简化cmake文件:
cmake_minimum_required(VERSION 3.2)
project(segslam C CXX)
set(CMAKE_CXX_STANDARD 11)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/poco")
find_package(Poco REQUIRED)
#include($ENV{CINDER_PATH}/proj/cmake/configure.cmake)
#set(cinder_DIR $ENV{CINDER_PATH}/${CINDER_LIB_DIRECTORY})
#find_package(cinder REQUIRED PATHS " $ENV{CINDER_PATH}/${CINDER_LIB_DIRECTORY}")
add_executable(BasicApp BasicApp.cpp)
#target_include_directories(BasicApp PUBLIC $ENV{CINDER_PATH}/include)
#target_link_libraries(BasicApp cinder)
target_link_libraries(BasicApp ${Poco_LIBRARIES})
set_target_properties(BasicApp PROPERTIES
DEBUG_POSTFIX "d"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
install(TARGETS BasicApp RUNTIME DESTINATION bin COMPONENT main)
install(FILES ${srcs} DESTINATION app COMPONENT main)
如果注释行被取消注释,它会在cinder中链接并且事情会中断。我正在使用here中的FindPoco.cmake文件。 cinder cmake文件位于here。
链接顺序似乎并不重要,我使用的其他库都没有这个问题。
答案 0 :(得分:1)
事实证明,问题是ABI不匹配。 Cinder附带了使用gcc版本< 5.1的预编译boost库,如果您尝试使用已使用gcc版本> = 5.1编译的库,则会导致冲突。
我的解决方法是删除cinder预编译的boost库,并使用ubuntu repos中的boost版本重新编译。
有关详细信息,请参阅cinder话语中的this主题。