简体   繁体   中英

link to boost::thread fails

I'm trying to install a program called mgiza. It compiles with CMake and requires some boost libraries. I used the commands

cmake .
make

When I run 'make' I get the following errors:

d4norm.cxx:(.text+0x95b): undefined reference to `boost::system::generic_category()'

and the likes. I inserted the following line in cmakelists.txt:

FIND_PACKAGE( Boost 1.41 COMPONENTS system)

it worked because more files could be compiled and the warning above disappeared, but I got another warnings:

main.cpp:(.text+0x7174): undefined reference to `boost::thread::hardware_concurrency()'

although I already have the FIND_PACKAGE( Boost 1.41 COMPONENTS thread) in the cmakelists. What am I doing wrong?

You also need to search for the thread component:

find_package(Boost 1.41 COMPONENTS thread system)

In newer versions of Boost.Thread you also should link against Boost.Chrono

find_package(Boost COMPONENTS thread chrono system)

Then you also need to link your executable against it and add the includes:

# Check if everything worked out
if(Boost_FOUND)
  add_executable(main main.cpp) # your executable or library or whatever
  target_link_libraries(main ${Boost_LIBRARIES})
  target_include_directories(main ${Boost_INCLUDE_DIRS})
else()
  # panic
endif()

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