[英]Error linking to Boost filesystem using cmake on cygwin
我正在使用cmake 2.8.9,g ++ 3.4.4和Boost 1.50。 在Windows 8 64位的Cygwin中。 這是我收到的錯誤消息。
鏈接CXX可執行文件RayTracer.exe CMakeFiles / RayTracer.dir / Ray_Tracer.cpp.o:Ray_Tracer.cpp :(。text + 0x89c):未定義引用
boost::system::generic_category()' CMakeFiles/RayTracer.dir/Ray_Tracer.cpp.o:Ray_Tracer.cpp:(.text+0x8a6): undefined reference to
boost :: system :: generic_category()'CMakeFiles / RayTracer.dir / Ray_Tracer.cpp.o:Ray_Tracer.cpp :(。text + 0x8b0) :對boost::system::system_category()' /usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../i686-pc-cygwin/bin/ld: CMakeFiles/RayTracer.dir/Ray_Tracer.cpp.o: bad reloc address 0xb in section
未定義引用boost::system::system_category()' /usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../i686-pc-cygwin/bin/ld: CMakeFiles/RayTracer.dir/Ray_Tracer.cpp.o: bad reloc address 0xb in section
.text $ _ZN5boost6system14error_categoryD1Ev [boost :: system :: error_category :: ~error_category()]'collect2:ld返回1退出狀態CMakeFiles / RayTracer.dir / build.make:94:目標RayTracer.exe' failed make[2]: *** [RayTracer.exe] Error 1 CMakeFiles/Makefile2:64: recipe for target
配方RayTracer.exe' failed make[2]: *** [RayTracer.exe] Error 1 CMakeFiles/Makefile2:64: recipe for target
CMakeFiles / RayTracer.dir / all的RayTracer.exe' failed make[2]: *** [RayTracer.exe] Error 1 CMakeFiles/Makefile2:64: recipe for target
失敗make [1]: * [CMakeFiles / RayTracer.dir / all]錯誤2 Makefile:75:目標`all'失敗的食譜make:* [全部]錯誤2
從我所看到的,通常的問題是無法鏈接升壓系統庫,但我確保這樣做。 這是我的CMakeLists.txt文件的相關部分:
#Edit: cmake can't find the static libraries on cygwin, so I'm setting this to false for now.
SET(Boost_USE_STATIC_LIBS FALSE)
FIND_PACKAGE(Boost 1.50 REQUIRED date_time program_options thread filesystem system unit_test_framework)
IF(${Boost_FOUND})
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ENDIF()
add_executable(RayTracer
Ray_Tracer.cpp
)
target_link_libraries(RayTracer ${Boost_PROGRAM_OPTIONS_LIBRARIES})
這是我的.cpp文件中觸發錯誤的行:
#include <boost/filesystem.hpp>
知道我做錯了什么嗎?
您需要告訴鏈接器鏈接Boost.Filesystem和Boost.System庫。
你可以做:
target_link_libraries(RayTracer
${Boost_PROGRAM_OPTIONS_LIBRARIES}
${Boost_FILESYSTEM_LIBRARIES}
${Boost_SYSTEM_LIBRARIES}
)
或者如果您只想鏈接find_package(Boost...)
調用中指定的所有lib,您可以執行以下操作:
target_link_libraries(RayTracer ${Boost_LIBRARIES})
有關FindBoost
CMake模塊的更多詳細信息,請參閱文檔或運行:
cmake --help-module FindBoost
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.