Visual Studio 2015/Linux extension produces a "collect2 : error : ld returned 1 exit status" with Cygwin

Visual Studio 2015/Linux extension produces a "collect2 : error : ld returned 1 exit status" with Cygwin

我目前正在尝试 Visual Studio 2015 年的 Linux Extension

我计划有几个目标机器使用各种 distribs。到目前为止,我的测试机器是 Windows 7,安装了 up-to-date Cygwin 和所有需要的包(opensshg++gdb...)。

我正在进行的测试包含一个非常简单的 C++ "Hello world" 文件,VS 项目设置是默认设置。

一切运行良好,但链接:

我尝试使用 g++ 在远程平台上编译此文件。没问题,生成了一个可执行文件并且可以运行。

我完全不明白。有什么想法吗?


如果需要,请提供详细信息:

好的,找到了!默认 VS/Linux 项目选项不适合 Cygwin:

将 VS 项目构建输出从 "minimal"(默认值)切换到 "normal" 时,我注意到生成的 ld 命令行存在问题:

1>       Link:
1>         Linking objects
1>         Invoking ld
1>         g++ -o "/home/xxxxx/projects/xxxxxx/bin/x86/Release/xxxxx.out" -Wl,--no-undefined -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack /home/xxxxx/projects/xxxxx/obj/x86/Release/main.o
1>         /bin/ld: unrecognized option '-z'
1>         /bin/ld: use the --help option for usage information
1>         collect2: error: ld returned 1 exit status

-z选项是not implemented on Cygwin and won't be。所以它必须从默认使用的 VS linker 选项中删除:

之前:

之后: 注 1:第三个必须手动设置为空白,因为两个建议的选项都使用 -z
注意 2:这两个屏幕截图之间的所有其他差异与此问题无关。第一个是我的 release 配置,默认保留,第二个是我的 debug 配置,使用 verbose 和 print-map。)

现在一切运行良好:

程序已正确构建,可以运行,并且 link 与 GDB 在调试模式下也可以正常运行。

警告:此 -z 之后从 Cygwin 切换到标准 Linux 平台时可能会出现问题。