我在我的机器上下载并安装了Rust和Cargo nightlies,并使用Cargo生成了一个新的二进制项目:
Cifram@Valyria ~
$ cargo new test --bin
然后我尝试运行这个处女项目,再次使用Rust和Cargo的新装置,并且得到了这个:
Cifram@Valyria ~/test
$ cargo run --verbose
Compiling test v0.0.1 (file:///C:/cygwin64/home/Cifram/test)
Running `rustc C:\cygwin64\home\Cifram\test\src\main.rs --crate-name test --crate-type bin -g --out-dir C:\cygwin64\home\Cifram\test\target --dep-info C:\cygwin64\home\Cifram\test\target\.fingerprint\test-51757ad0485ed143\dep-bin-test -L C:\cygwin64\home\Cifram\test\target -L C:\cygwin64\home\Cifram\test\target\deps`
error: linking with `gcc` failed: exit code: 1
note: gcc '-m64' '-L' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib' '-o' 'C:\cygwin64\home\Cifram\test\target\test.exe' 'C:\cygwin64\home\Cifram\test\target\test.o' '-Wl,--whole-archive' '-lmorestack' '-Wl,--no-whole-archive' '-fno-lto' '-fno-use-linker-plugin' '-Wl,--gc-sections' '-static-libgcc' '-Wl,--enable-long-section-names' '-Wl,--nxcompat' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libnative-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libstd-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libsync-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\librustrt-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libcollections-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\liballoc-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libunicode-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\liblibc-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\librand-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libcore-4e7c5e5c.rlib' '-L' 'C:\cygwin64\home\Cifram\test\target' '-L' 'C:\cygwin64\home\Cifram\test\target\deps' '-L' 'C:\cygwin64\home\Cifram\test\.rust' '-L' 'C:\cygwin64\home\Cifram\test' '-Wl,--whole-archive' '-Wl,-Bstatic' '-Wl,--no-whole-archive' '-Wl,-Bdynamic' '-lws2_32' '-lcompiler-rt'
note: C:\cygwin64\home\Cifram\test\target\test.o: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
error: aborting due to previous error
Could not compile `test`.
Caused by:
Process didn't exit successfully: `rustc C:\cygwin64\home\Cifram\test\src\main.rs --crate-name test --crate-type bin -g --out-dir C:\cygwin64\home\Cifram\test\target --dep-info C:\cygwin64\home\Cifram\test\target\.fingerprint\test-51757ad0485ed143\dep-bin-test -L C:\cygwin64\home\Cifram\test\target -L C:\cygwin64\home\Cifram\test\target\deps` (status=101)
我不确定为什么rustc正在调用gcc,因为我知道它是建立在LLVM之上的。我通过MinGW安装了gcc,所以我首先想到的可能是gcc安装正在干扰。
Cifram@Valyria ~
$ gcc -v
Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\gcc.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=mingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto --enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gmp-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)
所以它是gcc的最新版本。但是,它可能不是rustc所期待的。所以我从我的路径中删除了C:\ MinGW \ bin并再次尝试,然后得到了:
Cifram@Valyria ~/test
$ cargo run --verbose
Compiling test v0.0.1 (file:///C:/cygwin64/home/Cifram/test)
Running `rustc C:\cygwin64\home\Cifram\test\src\main.rs --crate-name test --crate-type bin -g --out-dir C:\cygwin64\home\Cifram\test\target --dep-info C:\cygwin64\home\Cifram\test\target\.fingerprint\test-51757ad0485ed143\dep-bin-test -L C:\cygwin64\home\Cifram\test\target -L C:\cygwin64\home\Cifram\test\target\deps`
error: linking with `gcc` failed: exit code: 1
note: gcc '-m64' '-L' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib' '-o' 'C:\cygwin64\home\Cifram\test\target\test.exe' 'C:\cygwin64\home\Cifram\test\target\test.o' '-Wl,--whole-archive' '-lmorestack' '-Wl,--no-whole-archive' '-fno-lto' '-fno-use-linker-plugin' '-Wl,--gc-sections' '-static-libgcc' '-Wl,--enable-long-section-names' '-Wl,--nxcompat' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libnative-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libstd-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\librand-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libsync-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\librustrt-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libcollections-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\liballoc-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\liblibc-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libunicode-4e7c5e5c.rlib' 'C:\Program Files (x86)\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libcore-4e7c5e5c.rlib' '-L' 'C:\cygwin64\home\Cifram\test\target' '-L' 'C:\cygwin64\home\Cifram\test\target\deps' '-L' 'C:\cygwin64\home\Cifram\test\.rust' '-L' 'C:\cygwin64\home\Cifram\test' '-Wl,--whole-archive' '-Wl,-Bstatic' '-Wl,--no-whole-archive' '-Wl,-Bdynamic' '-lws2_32' '-lcompiler-rt'
note: ld: this linker was not configured to use sysroots
error: aborting due to previous error
Could not compile `test`.
Caused by:
Process didn't exit successfully: `rustc C:\cygwin64\home\Cifram\test\src\main.rs --crate-name test --crate-type bin -g --out-dir C:\cygwin64\home\Cifram\test\target --dep-info C:\cygwin64\home\Cifram\test\target\.fingerprint\test-51757ad0485ed143\dep-bin-test -L C:\cygwin64\home\Cifram\test\target -L C:\cygwin64\home\Cifram\test\target\deps` (status=101)
嗯,这是一个有点不同的错误,但实际上并没有更好。相同的gcc命令失败,但是,在错误之前:
C:\cygwin64\home\Cifram\test\target\test.o: file not recognized: File format not recognized
现在它:
ld: this linker was not configured to use sysroots
我发现其中任何一个都非常有意义。我试过跑" rustc main.rs"直。得到了相同的错误(除了#34; src \ main.o"而不是" target \ test.o")。尝试从本机Windows命令行而不是cygwin执行所有这些操作。同样的错误。所以它似乎不是Cargo或cygwin的责任。我也尝试下载最后一个"稳定"释放Rust(0.12.0),仍然有同样的错误。我已经用Google搜索了这些错误,然后空了。所以我的想法已经不多了。
帮助?
答案 0 :(得分:2)
作为替代解决方案,我在从cygwin shell环境调用Rust时操纵了路径变量。我理解它的方式是Rust将使用系统路径,搜索gcc,然后尝试使用它。通过操纵路径来移除不想要的GCC,它将退回,并使用生锈安装程序附带的那个。
PATH =' / c / Program Files / Rust / bin'货物建造
*使用正确的cygwin路径到您安装Rust的位置。在我的系统上,这是/ c / Program ...
答案 1 :(得分:1)
成功!事实证明,问题是我在cygwin中安装了ld。所以从我所知道的,它使用的是作为rustc的一部分发布的gcc版本,但是gcc正在调用C:\ cygwin64 \ bin \ ld.exe,而不是它自己的内部ld。
一旦我删除ld,一切正常。
请注意,这强调了我在评论中提出的观点:显然我不能同时在同一台机器上进行Rust开发和C / C ++开发。即使是为了编译我希望在Rust中访问的C库,如SDL2或GLFW。这非常不方便。如果rustc需要特定版本的gcc和ld,并且附带正确的版本,则不应默认调用系统版本。如果需要覆盖它的gcc或ld版本,则应该通过显式命令行选项来完成。
修改:添加遗漏的“not”,无意中颠倒了句子的含义。