C++ Eclipse 生成无效的exe
Posted
技术标签:
【中文标题】C++ Eclipse 生成无效的exe【英文标题】:C++ Eclipse generates invalid exe 【发布时间】:2015-06-26 09:35:40 【问题描述】:我正在使用 C++ Eclipse 和 MinGW/MSYS 生态系统来编译我的 C++ 程序。我在我的系统变量中为 MinGW/MSYS 设置了正确的路径。在构建 EXE 时,也会使用名称 LibTest 创建一个 EXE,但它的格式为 x86/le。当我运行此 EXE 时,出现以下错误:
CreateProcess error=193, %1 is not a valid Win32 application
我在创建的 EXE 上使用了 Dependency walker,但出现以下错误
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: Modules with different CPU types were found.
我在下面附上构建日志:
**** Build of configuration Debug for project Test ****
make -k all
Building file: ../src/Test.cpp
Invoking: GCC C++ Compiler
g++ -I"C:\MinGW\include" -O0 -g3 -Wall -c -fmessage-length=0 -v -MMD -MP -MF"src/Test.d" -MT"src/Test.d" -o"src/Test.o" "../src/Test.cpp"
Using built-in specs.
COLLECT_GCC=c:\MinGW\bin\g++.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)
COLLECT_GCC_OPTIONS='-I' 'C:\MinGW\include' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-MMD' '-MP' '-MF' 'src/Test.d' '-MT' 'src/Test.d' '-o' 'src/Test.o' '-shared-libgcc' '-mtune=generic' '-march=pentiumpro'
c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/cc1plus.exe -quiet -v -I C:\MinGW\include -iprefix c:\mingw\bin\../lib/gcc/mingw32/4.8.1/ -MMD src/Test.d -MF src/Test.d -MP -MT src/Test.d -dD ../src/Test.cpp -quiet -dumpbase Test.cpp -mtune=generic -march=pentiumpro -auxbase-strip src/Test.o -g3 -O0 -Wall -version -fmessage-length=0 -o C:\Users\abc\AppData\Local\Temp\ccPn8RrE.s
GNU C++ (GCC) version 4.8.1 (mingw32)
compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include/c++"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include/c++/mingw32"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include/c++/backward"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../include"
ignoring duplicate directory "/mingw/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include-fixed"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
ignoring duplicate directory "C:\MinGW\include"
as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c++
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c++/mingw32
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c++/backward
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../include
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include-fixed
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../mingw32/include
End of search list.
GNU C++ (GCC) version 4.8.1 (mingw32)
compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 1ebc2a6f92fbd3aadc367a20a63fdf9f
COLLECT_GCC_OPTIONS='-I' 'C:\MinGW\include' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-MMD' '-MP' '-MF' 'src/Test.d' '-MT' 'src/Test.d' '-o' 'src/Test.o' '-shared-libgcc' '-mtune=generic' '-march=pentiumpro'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/as.exe -v -I C:\MinGW\include -o src/Test.o C:\Users\abc\AppData\Local\Temp\ccPn8RrE.s
GNU assembler version 2.24 (mingw32) using BFD version (GNU Binutils) 2.24
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/;c:/mingw/bin/../libexec/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.8.1/;c:/mingw/bin/../lib/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../
COLLECT_GCC_OPTIONS='-I' 'C:\MinGW\include' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-MMD' '-MP' '-MF' 'src/Test.d' '-MT' 'src/Test.d' '-o' 'src/Test.o' '-shared-libgcc' '-mtune=generic' '-march=pentiumpro'
Finished building: ../src/Test.cpp
Building target: libTest.exe
Invoking: MinGW C++ Linker
g++ -shared -o"libTest.exe" ./src/Test.o
Finished building target: libTest.exe
似乎一些 32 位库正在被选中。
但是,如果我使用命令行进行编译,则会生成正确的 EXE。
【问题讨论】:
您在哪个操作系统上遇到它?例如,为较新操作系统创建的二进制文件无法在 Windows XP 上运行。我不知道如何在 Eclipse 中“定位”,但这似乎是问题所在。 Win 7。skw 的回答解决了这个问题。 【参考方案1】:看来问题出在真正使用-shared
上。 -shared
仅适用于动态链接库 (.DLL
s)。对于构建应用程序 (.EXE
),您不应该使用它。 (我说的是你的makefile中的最后一个命令:g++ -shared -o"libTest.exe" ./src/Test.o
)
像这样构建它
g++ -o "libTest.exe" ./src/Test.o
【讨论】:
谢谢你亲爱的朋友。现在生成的二进制文件可以运行了。以上是关于C++ Eclipse 生成无效的exe的主要内容,如果未能解决你的问题,请参考以下文章
为 Linux 程序和 C++ 生成文件和使用 eclipse
Eclipse - lombok的@Slf4j和@Data无效