Home >Backend Development >C++ >How to Link a C Program with Boost Using CMake on Ubuntu?
Linking a C Program with Boost using CMake on Ubuntu
To link your program with the Boost library under Ubuntu using CMake, you can encounter errors such as "undefined reference to `boost::program_options::options_description::m_default_line_length'".
To resolve this, consider incorporating the following lines into your CMake file:
find_package(Boost 1.40 COMPONENTS program_options REQUIRED) include_directories(${Boost_INCLUDE_DIR}) add_executable(anyExecutable myMain.cpp) target_link_libraries(anyExecutable LINK_PUBLIC ${Boost_LIBRARIES})
This approach utilizes CMake's find_package mechanism to locate Boost, handles include directory manipulation, generates an executable named anyExecutable, and links it with the necessary Boost libraries.
The above is the detailed content of How to Link a C Program with Boost Using CMake on Ubuntu?. For more information, please follow other related articles on the PHP Chinese website!