gpt4 book ai didi

C++ Eclipse 生成无效的 exe

转载 作者:行者123 更新时间:2023-11-28 06:12:02 25 4
gpt4 key购买 nike

我正在使用 C++ Eclipse 和 MinGW/MSYS 生态系统来编译我的 C++ 程序。我在我的系统变量中为 MinGW/MSYS 设置了正确的路径。在构建时,还会创建一个名为 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。

最佳答案

问题似乎出在真正使用 -shared 上。 -shared 用于动态链接库(.DLL)。对于构建应用程序 (.EXE),您不应使用它。 (我说的是你的 makefile 中的最后一个命令:g++ -shared -o"libTest.exe"./src/Test.o)

像这样构建

g++ -o "libTest.exe"  ./src/Test.o 

关于C++ Eclipse 生成无效的 exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31069742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com