简体   繁体   中英

Error linking to Boost filesystem using cmake on cygwin

I'm using cmake 2.8.9, g++ 3.4.4, and Boost 1.50. in Cygwin on Windows 8 64 bit. Here is the error message I get.

Linking CXX executable RayTracer.exe CMakeFiles/RayTracer.dir/Ray_Tracer.cpp.o:Ray_Tracer.cpp:(.text+0x89c): undefined reference to 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): undefined reference to 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 returned 1 exit status CMakeFiles/RayTracer.dir/build.make:94: recipe for target RayTracer.exe' failed make[2]: *** [RayTracer.exe] Error 1 CMakeFiles/Makefile2:64: recipe for target CMakeFiles/RayTracer.dir/all' failed make[1]: * [CMakeFiles/RayTracer.dir/all] Error 2 Makefile:75: recipe for target `all' failed make: * [all] Error 2

From what I've seen, the usual problem is failing to link the boost system library, but I made sure to do that. Here is the relevant portion of my CMakeLists.txt file:

#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})

And here's the line in my .cpp file that triggers the error:

#include <boost/filesystem.hpp>

Any idea what I'm doing wrong?

You need to tell the linker to link Boost.Filesystem and Boost.System libraries.

You can do:

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

or if you just want to link all the libs specified in your find_package(Boost...) call, you can do:

target_link_libraries(RayTracer ${Boost_LIBRARIES})

For further details on the FindBoost CMake module, see the docs or run:

cmake --help-module FindBoost

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM