编译magnum-integration出现_ZGVZN5boost6system15system_categoryEvE24system_category_instance链接错误的解决方法

编译错误输出内容如下:

[ 11%] Building CXX object src/Magnum/BulletIntegration/CMakeFiles/MagnumBulletIntegration.dir/DebugDraw.cpp.o
[ 22%] Building CXX object src/Magnum/BulletIntegration/CMakeFiles/MagnumBulletIntegration.dir/MotionState.cpp.o
[ 33%] Linking CXX shared library ../../../lib/libMagnumBulletIntegration.so
[ 33%] Built target MagnumBulletIntegration
[ 44%] Building CXX object src/Magnum/DartIntegration/CMakeFiles/MagnumDartIntegration.dir/ConvertShapeNode.cpp.o
[ 55%] Building CXX object src/Magnum/DartIntegration/CMakeFiles/MagnumDartIntegration.dir/Object.cpp.o
[ 66%] Building CXX object src/Magnum/DartIntegration/CMakeFiles/MagnumDartIntegration.dir/World.cpp.o
[ 77%] Linking CXX shared library ../../../lib/libMagnumDartIntegration.so
/usr/bin/ld: /usr/local/lib/libboost_filesystem.a(operations.o): relocation R_X86_64_32 against `_ZGVZN5boost6system15system_categoryEvE24system_category_instance' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libboost_filesystem.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
src/Magnum/DartIntegration/CMakeFiles/MagnumDartIntegration.dir/build.make:133: recipe for target 'lib/libMagnumDartIntegration.so.2.3' failed
make[2]: *** [lib/libMagnumDartIntegration.so.2.3] Error 1
CMakeFiles/Makefile2:208: recipe for target 'src/Magnum/DartIntegration/CMakeFiles/MagnumDartIntegration.dir/all' failed
make[1]: *** [src/Magnum/DartIntegration/CMakeFiles/MagnumDartIntegration.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

解决方法:
从终端输出的编译错误可以看出,在链接静态库libboost_filesystem.a时出错。

解决办法如下:
修改magnum-integration/src/Magnum/DartIntegration/CMakeLists.txt文件中的链接语句。

......
# DartIntegration library
add_library(MagnumDartIntegration ${SHARED_OR_STATIC}
    ${MagnumDartIntegration_SRCS}
    ${MagnumDartIntegration_HEADERS})
target_include_directories(MagnumDartIntegration PUBLIC
    ${PROJECT_SOURCE_DIR}/src
    ${PROJECT_BINARY_DIR}/src)
set_target_properties(MagnumDartIntegration PROPERTIES
    DEBUG_POSTFIX "-d"
    FOLDER "Magnum/DartIntegration")
if(NOT BUILD_STATIC)
    set_target_properties(MagnumDartIntegration PROPERTIES VERSION ${MAGNUM_LIBRARY_VERSION} SOVERSION ${MAGNUM_LIBRARY_SOVERSION})
elseif(BUILD_STATIC_PIC)
    set_target_properties(MagnumDartIntegration PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
target_link_libraries(MagnumDartIntegration
    Magnum::GL
    Magnum::Magnum
    Magnum::SceneGraph
    Magnum::Primitives
    Magnum::MeshTools
    dart
	-lboost_filesystem) #添加静态链接libboost_filesystem.a的参数

install(TARGETS MagnumDartIntegration
    RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}
    LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}
    ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
install(FILES ${MagnumDartIntegration_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/DartIntegration)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/configure.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/DartIntegration)

if(BUILD_TESTS)
    add_subdirectory(Test)
endif()

# Magnum DART integration target alias for superprojects
add_library(MagnumIntegration::Dart ALIAS MagnumDartIntegration)

接着执行

cmake ..
make cleam
make

最后编译通过:

[ 11%] Building CXX object src/Magnum/BulletIntegration/CMakeFiles/MagnumBulletIntegration.dir/DebugDraw.cpp.o
[ 22%] Building CXX object src/Magnum/BulletIntegration/CMakeFiles/MagnumBulletIntegration.dir/MotionState.cpp.o
[ 33%] Linking CXX shared library ../../../lib/libMagnumBulletIntegration.so
[ 33%] Built target MagnumBulletIntegration
[ 44%] Building CXX object src/Magnum/DartIntegration/CMakeFiles/MagnumDartIntegration.dir/ConvertShapeNode.cpp.o
[ 55%] Building CXX object src/Magnum/DartIntegration/CMakeFiles/MagnumDartIntegration.dir/Object.cpp.o
[ 66%] Building CXX object src/Magnum/DartIntegration/CMakeFiles/MagnumDartIntegration.dir/World.cpp.o
[ 77%] Linking CXX shared library ../../../lib/libMagnumDartIntegration.so
[ 77%] Built target MagnumDartIntegration
Scanning dependencies of target MagnumGlmIntegration
[ 88%] Building CXX object src/Magnum/GlmIntegration/CMakeFiles/MagnumGlmIntegration.dir/Integration.cpp.o
[100%] Linking CXX shared library ../../../lib/libMagnumGlmIntegration.so
[100%] Built target MagnumGlmIntegration

你可能感兴趣的:(Magnum)