Visual Studio C ++远程Linux调试添加链接器选项 [英] Visual Studio C++ remote linux debugging add linker options

查看:337
本文介绍了Visual Studio C ++远程Linux调试添加链接器选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Boost库在C ++中开发一个简单的程序. 我使用Visual Studio 2017和ubuntu的远程bash shell进行编译和调试.

I am trying to develop a simple program in C++ with the boost library. I develop with Visual Studio 2017 and a remote bash shell of ubuntu to compile and debug.

我在ubuntu上安装了gdb,gdbserver,所有编译器和boost库.

I installed gdb, gdbserver, all the compiler and the boost library on ubuntu.

无需boost的简单程序就可以像在Visual Studio中一样直接从shell编译和运行,而不会出现问题!

Simple programs without boost compile and run without problem from the shell directly as from Visual Studio !

当我使用以下命令直接从ubuntu bash编译以下程序时:g++ test.cpp -std=c++11 -lboost_program_options -o t它也会编译并运行!

When I compile the following program directly from the ubuntu bash with the following command : g++ test.cpp -std=c++11 -lboost_program_options -o t It compiles and runs also!

#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中的文件中,然后尝试远程编译,那么它将无法正常工作:

But if I put the same code in Visual Studio in a file and try to compile remotely it doesn't work :

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 ++>所有选项>其他选项 和下: 配置属性>链接器>所有选项>其他选项

In the project properties I have included -lboost_program_options under : Configuration Properties > C/C++ > All Options > Additional Options and under : Configuration Properties > Linker > All Options > Additional Options

我在做什么错了?

推荐答案

以下是VCLinux用于为GCC指定库的规则-从

Below are the rules used by VCLinux for specifying libraries to GCC - from Ion Todirel (MSFT) in an answer on the VCLinux GitHub site.

您将看到...Additional Options将库放在目标文件之前,因此链接程序不会在库中查找依赖项.我建议使用Linker - Input - Library Dependencies并指定库名称boost_program_options而不使用-l.

You will see that ...Additional Options puts the library before the object files and hence the linker won't look in the library for dependencies. I'd recommend using Linker - Input - Library Dependencies and specify the library name, boost_program_options without the -l .

  • 链接器-常规-其他库目录-这添加了路径 用-L到命令开头附近的链接器命令行 行.

  • Linker - General - Additional Library Directories - this adds paths with -L to the linker command line near the beginning of the command line.

链接器-输入-库依赖关系-这将文件名添加为 -l位于链接器命令行的最后

Linker - Input - Library Dependencies - this adds the file names with -l at the very end of the linker command line

链接器-输入-其他依赖关系-这将添加条目 在目标文件之后和链接器-输入-之前逐字记录 库依赖项

Linker - Input - Additional Dependencies - this adds the entries verbatim after the object files, and before the Linker - Input - Library Dependencies

链接器-命令行-其他选项-这将添加条目 在链接器命令行中的目标文件之前逐字显示

Linker - Command Line - Additional Options - this adds the entries verbatim before the object files in the linker command line

请注意,在Linker - Input - Library Dependencies中给定的库名称作为-l命令行选项传递给gcc.即它不应具有lib前缀或扩展名.例如,libcairo.so应该在Linker - Input - Library Dependencies中显示为cairo.在Linux遥控器上,gcc将沿着Linker - General - Additional Library Directories指定的路径搜索,并且默认的系统库搜索路径首先寻找libcairo.so(动态链接或共享的库),然后寻找libcairo.a(静态链接).库).

Note that the library name given in Linker - Input - Library Dependencies is passed to gcc as a -l command line option; i.e. it should not have the lib prefix or an extension. For example, libcairo.so should appear in Linker - Input - Library Dependencies as cairo. On the Linux remote, gcc will search along the path(s) specified in Linker - General - Additional Library Directories and the default system library search paths looking first for libcairo.so (dynamically linked, or shared, library) then libcairo.a (statically linked library).

如果系统上同时具有共享库和静态库,则将优先使用共享库.如果要强制链接静态库,请参见告诉gcc直接链接一个静态库.

If you have both shared and static libraries on your system, the shared library will be used preferrentially. If you want force linking of the static library see Telling gcc directly to link a library statically.

这篇关于Visual Studio C ++远程Linux调试添加链接器选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆