Closed david-alvarez-rosa closed 1 year ago
I'm trying to link against boost/program_options library with a dummy program main.cpp
boost/program_options
main.cpp
#include <boost/program_options.hpp> int main() { boost::program_options::options_description desc("My description"); }
by using the following CMakeLists.txt
CMakeLists.txt
cmake_minimum_required(VERSION 3.10) project(my-project) find_package(Boost 1.82 REQUIRED) add_executable(exe "main.cpp") target_include_directories(exe PRIVATE ${Boost_INCLUDE_DIR}) target_link_libraries(exe ${Boost_LIBRARIES})
And I'm getting the following error
$ cmake -B build ... [Succeeds] $ cmake --build build -v ... [100%] Linking CXX executable exe /opt/homebrew/Cellar/cmake/3.27.6/bin/cmake -E cmake_link_script CMakeFiles/exe.dir/link.txt --verbose=1 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -mmacosx-version-min=13.6 -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/exe.dir/main.cpp.o -o exe ld: Undefined symbols: boost::program_options::options_description::m_default_line_length, referenced from: _main in main.cpp.o boost::program_options::options_description::options_description(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, unsigned int, unsigned int), referenced from: _main in main.cpp.o clang: error: linker command failed with exit code 1 (use -v to see invocation)
However, surprisingly, when compiling manually it works
$ clang++ -I/opt/homebrew/include -L/opt/homebrew/lib -lboost_program_options main.cpp
I've been using Boost libraries in this same project, so I'm not sure what could be going wrong.
Any pointers appreciated!
I've Boost libraries installed (v. 1.82) directly by Homebrew
$ brew install boost
Solved by
find_package(Boost 1.65 COMPONENTS program_options REQUIRED)
I'm trying to link against
boost/program_options
library with a dummy programmain.cpp
by using the following
CMakeLists.txt
And I'm getting the following error
However, surprisingly, when compiling manually it works
I've been using Boost libraries in this same project, so I'm not sure what could be going wrong.
Any pointers appreciated!