What should my CMake file look like for linking my program with the Boost library under Ubuntu?
The errors shown during running make:
main.cpp:(.text+0x3b): undefined reference to `boost::program_options::options_description::m_default_line_length'
The main file is really simple:
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/option.hpp>
using namespace std;
#include <iostream>
namespace po = boost::program_options;
int main(int argc, char** argv) {
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
;
return 0;
}
I’ve managed to do that. The only lines that I’ve added to my CMake files were:
target_link_libraries(
my_target_file
${Boost_PROGRAM_OPTIONS_LIBRARY}
)
In CMake you could use
find_packageto find libraries you need. There usually is aFindBoost.cmakealong with your CMake installation.As far as I remember, it will be installed to
/usr/share/cmake/Modules/along with other find-scripts for common libraries. You could just check the documentation in that file for more information about how it works.An example out of my head:
I hope this code helps.