【发布时间】:2018-03-22 08:01:39
【问题描述】:
我正在尝试使用 boost 库在 C++ 中开发一个简单的程序。 我使用 Visual Studio 2017 和 ubuntu 的远程 bash shell 进行编译和调试。
我在ubuntu上安装了gdb、gdbserver、所有编译器和boost库。
没有 boost 的简单程序可以直接从 shell 编译和运行,就像从 Visual Studio 一样!
当我使用以下命令直接从 ubuntu bash 编译以下程序时:g++ test.cpp -std=c++11 -lboost_program_options -o t 它也会编译并运行!
#include <boost/program_options.hpp>
#include <iostream>
using namespace boost::program_options;
int main(int argc, const char *argv[])
{
try
{
options_description desc{ "Options" };
desc.add_options()
("help,h", "Help screen");
variables_map vm;
store(parse_command_line(argc, argv, desc), vm);
notify(vm);
if (vm.count("help"))
std::cout << desc << '\n';
}
catch (const error &ex)
{
std::cerr << ex.what() << '\n';
}
}
但是如果我将相同的代码放在 Visual Studio 中的一个文件中并尝试远程编译它就不起作用:
1>------ Build started: Project: ACO-PPS, Configuration: Debug x64 ------
1>Validating architecture
1>Validating sources
1>Copying sources remotely to 'localhost'
1>Starting remote build
1>Compiling sources:
1>main.cpp
1>Linking objects
1>/home/marius/projects/ACO-PPS/obj/x64/Debug/main.o : In the function main :
1>/home/marius/projects/ACO-PPS/main.cpp:11 : undefined reference to « boost::program_options::options_description::m_default_line_length »
等等……
在项目属性中,我将-lboost_program_options 包含在:
配置属性 > C/C++ > 所有选项 > 附加选项
和下:
配置属性 > 链接器 > 所有选项 > 附加选项
我做错了什么?
【问题讨论】:
标签: visual-studio ubuntu boost remote-debugging boost-program-options