我在Linux& amp;写了一个C ++程序。我在其中使用了像unistd.h
这样的Linux标题。
现在我必须为Windows&编译它我使用Cygwin with g++
。
但是在中它很清楚,它会编译一次&当我在那之后再次编译时,它会出现错误" g++: error: spawn: Exec format error
"
为什么会发生这种情况&我应该怎么做才能解决它?
ps:g++ myfile.cpp -v
输出:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-cygwin/4.7.3/lto-wrapper.exe
Target: i686-pc-cygwin
Configured with: /cygdrive/i/szsz/git/cygwin-ports-gcc/gcc-4.7.3-1/src/gcc-4.7.3/configure --srcdir=/cygdrive/i/szsz/git/cygwin-ports-gcc/gcc-4.7.3-1/src/gcc-4.7.3 --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --datadir=/usr/share --localstatedir=/var --sysconfdir=/etc --datarootdir=/usr/share --docdir=/usr/share/doc/gcc -C --build=i686-pc-cygwin --host=i686-pc-cygwin --target=i686-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --disable-__cxa_atexit --with-dwarf2 --with-arch=i686 --with-tune=generic --disable-sjlj-exceptions --enable-languages=ada,c,c++,fortran,java,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-support --enable-libssp --enable-libada --enable-libjava --enable-libgcj-sublibs --disable-java-awt --disable-symvers --with-ecj-jar=/usr/share/java/ecj.jar --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-ppl --with-system-zlib : (reconfigured) /cygdrive/i/szsz/git/cygwin-ports-gcc/gcc-4.7.3-1/src/gcc-4.7.3/configure --srcdir=/cygdrive/i/szsz/git/cygwin-ports-gcc/gcc-4.7.3-1/src/gcc-4.7.3 --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --datadir=/usr/share --localstatedir=/var --sysconfdir=/etc --datarootdir=/usr/share --docdir=/usr/share/doc/gcc -C --build=i686-pc-cygwin --host=i686-pc-cygwin --target=i686-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --disable-__cxa_atexit --with-dwarf2 --with-arch=i686 --with-tune=generic --disable-sjlj-exceptions --enable-languages=ada,c,c++,fortran,java,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-support --enable-libssp --enable-libada --enable-libjava --enable-libgcj-sublibs --disable-java-awt --disable-symvers --with-ecj-jar=/usr/share/java/ecj.jar --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-ppl --with-system-zlib
Thread model: posix
gcc version 4.7.3 (GCC)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=i686'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/cc1plus.exe -quiet -v -D__CYGWIN32__ -D__CYGWIN__ -Dunix -D__unix__ -D__unix -idirafter /usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../../include/w32api -idirafter ../../include/w32api tro_client.cpp -quiet -dumpbase tro_client.cpp -mtune=generic -march=i686 -auxbase tro_client -version -o /tmp/ccDDULRP.s
GNU C++ (GCC) version 4.7.3 (i686-pc-cygwin)
compiled by GNU C version 4.7.3, GMP version 4.3.2, MPFR version 3.0.1-p4, MPC version 1.0.1
warning: MPFR header version 3.0.1-p4 differs from library version 3.1.2.
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=32696
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../../i686-pc-cygwin/include"
ignoring nonexistent directory "../../include/w32api"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/i686-pc-cygwin/4.7.3/include/c++
/usr/lib/gcc/i686-pc-cygwin/4.7.3/include/c++/i686-pc-cygwin
/usr/lib/gcc/i686-pc-cygwin/4.7.3/include/c++/backward
/usr/lib/gcc/i686-pc-cygwin/4.7.3/include
/usr/local/include
/usr/lib/gcc/i686-pc-cygwin/4.7.3/include-fixed
/usr/include
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../../include/w32api
End of search list.
GNU C++ (GCC) version 4.7.3 (i686-pc-cygwin)
compiled by GNU C version 4.7.3, GMP version 4.3.2, MPFR version 3.0.1-p4, MPC version 1.0.1
warning: MPFR header version 3.0.1-p4 differs from library version 3.1.2.
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=32696
Compiler executable checksum: 32d481c3b6460a57b566c5b2698c9e31
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=i686'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../../i686-pc-cygwin/bin/as.exe -v -o /tmp/cc0pZbht.o /tmp/ccDDULRP.s
g++: error: spawn: Exec format error
答案 0 :(得分:0)
我今天偶然发现了同样的问题 - 并提出了一种深奥的解决方案,我将在此处添加以供参考。
我的问题是,编译器工具链 - 一个64位的cygwin gcc - 必须检查到修订控制系统。不幸的是,这个RCS不仅会混淆行结尾,还会删除文件属性。在我的情况下,文件S
(在我的案例中位于aarch64-unknown-elf文件夹中)缺少as.exe
(系统)文件属性。
最初未为S
设置as.exe
属性:
C:\gccInstallDir\arm\v8hf\aarch64-unknown-elf\bin>attrib as.exe
A C:\gccInstallDir\arm\v8hf\aarch64-unknown-elf\bin\as.exe
当尝试在Windows 7 64位上编译时,我得到:
arm_v8hf-gcc: error: spawn: Exec format error
但是设置了属性:
C:\gccInstallDir\arm\v8hf\aarch64-unknown-elf\bin>attrib +S as.exe
C:\gccInstallDir\arm\v8hf\aarch64-unknown-elf\bin>attrib as.exe
A S C:\gccInstallDir\arm\v8hf\aarch64-unknown-elf\bin\as.exe
编译工作正常!
我不知道为什么as.exe
需要成为系统文件,但是当我尝试从命令行调用as.exe
时,我收到一条消息,指出as.exe
不兼容使用当前的Windows版本。