0
votes

I am using the Boost library and I am having some linker issues. Currently my code is outputting this:

Undefined symbols for architecture x86_64: "boost::program_options::to_internal(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&)", referenced from: std::__1::vector<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > > > boost::program_options::to_internal<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > >(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > > > const&) in train_model_main.cc.o "boost::program_options::variables_map::variables_map()", referenced from: _main in train_model_main.cc.o (THE LIST CONTINUES)

At the bottom my code says this:

ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am trying to use the program_options library from Boost, but the linking step seems to be failing. Here is how I link in my CMake file:

find_package(Boost 1.73.0 COMPONENTS program_options REQUIRED)
if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS})
    add_executable(main ./apps/something.cc)
    target_link_libraries( main program_options)
endif()

I believe that I am correctly linking the library, so what could be causing this issue?

1

1 Answers

0
votes

I'm gonna copy and paste the answer from the cmake discourse: https://discourse.cmake.org/t/boost-linker-issues/2030

"I believe that I am correctly linking the libraryā€¯ unfortunately not. You need to reference the full target name including the namespace prefix with Boost::program_options. And you can omit adding the Boost_INCLUDE_DIRS explicitely as the target definition does include this information. So your lines would look like:" - Volker Enderlein

if(Boost_FOUND)
    add_executable(main ./apps/something.cc)
    target_link_libraries(main PUBLIC Boost::program_options)
endif()