2016-10-22 176 views
2

我目前正在Visual Studio中的Linux Extension 2015年的Visual Studio 2015/Linux的扩展产生了“collect2:错误:LD返回1个退出状态”使用Cygwin

我计划要使用不同的发行商几个目标机器。到目前为止,我的测试机器是安装了所有必需软件包(opensshg++,gdb ...)的最新Cygwin的Windows 7。

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

一切运行良好,但联动:

  • 架构是由Visual Studio
  • 源文件是由VS扩展
  • 他们做编译使用G ++
  • 正确复制到目标计算机识别但过程结束了一个"collect2 : error : ld returned 1 exit status"

我试图编译这个文件在远程平台上,使用g ++。没问题,一个可执行文件被生成并且工作。

我绝对不明白。任何想法?


详细信息,如果需要:

  • 我的C++源文件:

    #include <cstdio> 
    
    int main() 
    { 
        printf("hello from SandboxLinux!\n"); 
        return 0; 
    } 
    
  • 我的项目设置(远程设置和连接器设置,在我看没有什么特别):

Project settings Linker settings

  • 我的Visual Studio生成日志:

enter image description here

  • 在远程机器上:
    • main.cpp已正确复制
    • .o文件是否正确产生
    • .exe( “.out”)不
    • 项目的根,objbin目录如下:

enter image description here enter image description here enter image description here

  • w ^直接在远程机器上使用g++
    • g++ main.cpp无声地终止并产生一个工作的a.exe
    • 使用g++ -v没有显示相关

回答

0

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

当开关从“最小”(默认)“正常”我注意到有一个与生成ld命令行的一个问题构建输出的VS项目:

enter image description here

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 Cygwinwon't be。因此,它必须从VS连接选项删除它默认情况下使用:

前: enter image description here

后: enter image description here注1:第三个必须手动设置为空白既是建议选择使用-z
注2:这两个截屏之间的所有其他差异是不依赖于这一问题,首先是我release配置,默认情况下,保持在第二个是我debug配置,使用冗长和打印地图)

现在一切都运行良好。 enter image description here

程序正常建造,它的工作原理,并与GDB的链接也能正常工作在调试模式。

警告:这个-z事情可能是一个问题时,从Cygwin切换到标准的Linux平台稍后。

相关问题