“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:
if(Boost_FOUND)
add_executable(main ./apps/something.cc)
target_link_libraries(main PUBLIC Boost::program_options)
endif()
What platform are you on, what version of Boost are you trying to link to and how does your find_package command for Boost does look like (including all settings for Boost)?
A typical command sequence for Boost in my CMakeLists.txt looks like this:
I am on MacOS. I am using Boost Version 1.73.0. My find_package:
find_package(Boost 1.73.0 COMPONENTS program_options REQUIRED)
After making the changes you suggested, I received the “fatal error: ‘boost/program_options.hpp’ file not found” which occurred once 87% of the build was complete. After adding " INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})" outside of the endif() the build completes but then I get the same issue as before (Undefined symbols for architecture x86_64:, etc and at the bottom it says: NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation))
The target I built with add_executable is the file I am running from (the main method). I get these errors when running something.cc. Also, “Linking CXX executable train-model” train-model is something.cc.
I installed it via Homebrew. However, I initially installed it from the website (the .tar file). I installed it via homebrew without uninstalling the .tar files. After installing it via homebrew, I deleted the .tar files.