在Ubuntu下,将我的程序与Boost库链接的CMake文件应该是怎样的?
运行make
时显示的错误信息:
main.cpp:(.text+0x3b): undefined reference to `boost::program_options::options_description::m_default_line_length'
主要文件非常简单:
#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;
}
我已经做到了。我在我的CMake文件中添加的唯一行是:target_link_libraries(
my_target_file
${Boost_PROGRAM_OPTIONS_LIBRARY}
)
target_link_libraries
放在add_executable
和find_package
行之后,以便所有链接的组件都得到识别。 - Murphy