Reputation: 101
I'm trying to build a C++ executable that uses a Boost library. Building with CMake.
CMake snippet:
find_package(Boost REQUIRED system)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(main src/cpp/main.cpp)
target_link_libraries(main ${BOOST_LIBRARIES})
Getting following CMake build error message:
Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
...
Why am I getting the error and how can I fix it?
Upvotes: 3
Views: 1605
Reputation: 15996
To complete seeekr's answer, you should consider using imported target instead of Boost_
variables:
find_package(Boost REQUIRED system)
add_executable(main ...)
target_link_libraries(main Boost::system)
The imported target will handle linkage, include directories, compile definitions, and all needed stuff with a single call.
Upvotes: 3
Reputation: 101
The variables created by the find_package(Boost ...)
call you are using are case sensitive, i.e.
${BOOST_LIBRARIES}
will be empty and you need to make sure you are using it like this:
${Boost_LIBRARIES}
The same goes for Boost_INCLUDES
which you have used (read: copy-pasted) correctly here:
include_directories(${Boost_INCLUDE_DIRS})
Upvotes: 3