我的CMake文件在将我的程序与Ubuntu下的Boost库链接时应该是什么样的?
运行期间显示的错误make:
main.cpp:(.text+0x3b): undefined reference to `boost::program_options::options_description::m_default_line_length'
Run Code Online (Sandbox Code Playgroud)
主文件非常简单:
#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;
}
Run Code Online (Sandbox Code Playgroud)
我成功地做到了.我添加到CMake文件的唯一行是:
target_link_libraries(
my_target_file
${Boost_PROGRAM_OPTIONS_LIBRARY}
)
Run Code Online (Sandbox Code Playgroud)