C++ Eclipse generates invalid exe

时间:2015-06-26 09:35:40

标签: c++ eclipse gcc build mingw

I am using C++ Eclipse and MinGW/MSYS ecosystem for compiling my C++ programs. I set the correct paths for MinGW/MSYS in my system variables. On building an EXE is also created with the name LibTest however it says x86/le in the format. When I run this EXE I get the below error :

CreateProcess error=193, %1 is not a valid Win32 application

I used the Dependency walker on the created EXE and I got the below error

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.

I am attaching the Build Log below :

**** 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

It seems that some 32 bit libraries are getting picked.

However if I compile using a command line a correct EXE is getting generated.

1 个答案:

答案 0 :(得分:1)

It seems the problem is in really using -shared. -shared is for dynamic link libraries (.DLLs) only. For building an application (.EXE) you should not use it. (I am talking about the last command in your makefile: g++ -shared -o"libTest.exe" ./src/Test.o)

Build it like

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