使用cygwin上的cmake链接到Boost文件系统时出错

时间:2013-03-31 17:31:12

标签: c++ boost cygwin cmake

我正在使用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 :(文字+ 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 :(文字+ 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 的未定义引用.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 CMakeFiles / RayTracer.dir / all'失败make [1]: *   [CMakeFiles / RayTracer.dir / all]错误2 Makefile:75:目标的配方   'all'失败了make:* [all]错误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>

知道我做错了吗?

1 个答案:

答案 0 :(得分:2)

您需要告诉链接器链接Boost.Filesystem和Boost.System库。

你可以这样做:

target_link_libraries(RayTracer
                      ${Boost_PROGRAM_OPTIONS_LIBRARIES}
                      ${Boost_FILESYSTEM_LIBRARIES}
                      ${Boost_SYSTEM_LIBRARIES}
                      )

或者如果您只想链接find_package(Boost...)电话中指定的所有图书馆,您可以这样做:

target_link_libraries(RayTracer ${Boost_LIBRARIES})

有关FindBoost CMake模块的详细信息,请参阅the docs或运行:

cmake --help-module FindBoost
相关问题