1

I am using Cygwin on 64-bit Windows 8.1.

I wanted to make native windows executables inside the Cygwin environment (i.e. I didn't want to deal with cygwin dll issues). I saw Cygwin had minGW packages so I downloaded the

  • i686-pc-mingw32-gcc
  • x86_64-w64-mingw32-gcc

packages. From this post I've gathered the i686 one is 32-bit and the x86_64 one is 64-bit.

I used both the i686 and x86_64 version of g++ to compile a simple hello world program and both compiled without error.

The executable compiled by the i686 works as expected.

My problem: When I try to run the executable compiled by the x86_64 version, I get an windows error box saying "The application was unable to start correctly (0x000007b). Click OK to close the application."

I am very confused by this. Why does the 32-bit compiler work and the 64-bit compiler not work on my system?

In case it helps, here the stuff the x86_64 compiler is doing when I call it

$ x86_64-w64-mingw32-g++ test.cpp -o dd -v
Using built-in specs.

COLLECT_GCC=x86_64-w64-mingw32-g++

COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-w64-mingw32/4.9.2/lto-wrapper.exe

Target: x86_64-w64-mingw32

Configured with: /cygdrive/i/szsz/tmpp/cygwin64/mingw64-x86_64/mingw64-            x86_64-gc                                                                                                                                                              c-4.9.2-1.x86_64/src/gcc-4.9.2/configure --srcdir=/cygdrive/i/szsz/tmpp/cygwin64                                                                                                                                                              /mingw64-x86_64/mingw64-x86_64-gcc-4.9.2-1.x86_64/src/gcc-4.9.2 --prefix=/usr --                                                                                                                                                              exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/                                                                                                                                                              mingw64-x86_64-gcc --htmldir=/usr/share/doc/mingw64-x86_64-gcc/html -C --build=x                                                                                                                                                              86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-w64-mingw32 --without-li                                                                                                                                                             biconv-prefix --without-libintl-prefix --with-sysroot=/usr/x86_64-w64-mingw32/sy                                                                                                                                                              s-root --with-build-sysroot=/usr/x86_64-w64-mingw32/sys-root --disable-multilib                                                                                                                                                               --disable-win32-registry --enable-languages=c,ada,c++,fortran,lto,objc,obj-c++ -                                                                                                                                                              -enable-fully-dynamic-strings --enable-graphite --enable-libgomp --enable-libqua                                                                                                                                                              dmath --enable-libquadmath-support --enable-libssp --enable-version-specific-run                                                                                                                                                             time-libs --with-dwarf2 --with-gnu-ld --with-gnu-as --with-tune=generic --with-c                                                                                                                                                              loog-include=/usr/include/cloog-isl --with-system-zlib --libexecdir=/usr/lib

Thread model: win32

gcc version 4.9.2 (GCC)

COLLECT_GCC_OPTIONS='-o' 'dd.exe' '-v' '-shared-libgcc' '-mtune=generic' '- march                                                                                                                                                              =x86-64'
 /usr/lib/gcc/x86_64-w64-mingw32/4.9.2/cc1plus.exe -quiet -v -U_REENTRANT test.c                                                                                                                                                               pp -quiet -dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test -version                                                                                                                                                               -o /tmp/ccKIncrs.s

GNU C++ (GCC) version 4.9.2 (x86_64-w64-mingw32)
    compiled by GNU C version 4.9.2, GMP version 6.0.0, MPFR version 3.1.2-p                                                                                                                                                              11, MPC version 1.0.3

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/x86_64-w64-mingw32/sys-  root/usr/local/inclu                                                                                                                                                              de"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-w64-  mingw32/4.9.2/../../../.                                                                                                                                                              ./x86_64-w64-mingw32/include"

\#include "..." search starts here:

\#include <...> search starts here:
 /usr/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++
 /usr/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32
 /usr/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/backward
 /usr/lib/gcc/x86_64-w64-mingw32/4.9.2/include
 /usr/lib/gcc/x86_64-w64-mingw32/4.9.2/include-fixed
 /usr/x86_64-w64-mingw32/sys-root/mingw/include
  End of search list.

GNU C++ (GCC) version 4.9.2 (x86_64-w64-mingw32)
    compiled by GNU C version 4.9.2, GMP version 6.0.0, MPFR version 3.1.2-p                                                                                                                                                              11, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072

Compiler executable checksum: aee7f7b7ca14852762daf4c41db46c26

COLLECT_GCC_OPTIONS='-o' 'dd.exe' '-v' '-shared-libgcc' '-mtune=generic' '- march                                                                                                                                                              =x86-64'
 /usr/lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64- mingw32/bin/as.exe                                                                                                                                                               -v -o /tmp/ccSHmwxw.o /tmp/ccKIncrs.s
GNU assembler version 2.25.51 (x86_64-w64-mingw32) using BFD version (GNU  Binuti                                                                                                                                                               ls) 2.25.51.20150320

COMPILER_PATH=/usr/lib/gcc/x86_64-w64-mingw32/4.9.2/:/usr/lib/gcc/x86_64-w64-min                                                                                                                                                              gw32/4.9.2/:/usr/lib/gcc/x86_64-w64-mingw32/:/usr/lib/gcc/x86_64-w64-mingw32/4.9                                                                                                                                                              .2/:/usr/lib/gcc/x86_64-w64-mingw32/:/usr/lib/gcc/x86_64-w64-mingw32/4.9.2/../..                                                                                                                                                             /../../x86_64-w64-mingw32/bin/

LIBRARY_PATH=/usr/lib/gcc/x86_64-w64-mingw32/4.9.2/:/usr/lib/gcc/x86_64-w64- ming                                                                                                                                                              w32/4.9.2/../../../../x86_64-w64-mingw32/lib/../lib/:/usr/x86_64-w64-mingw32/sys                                                                                                                                                              -root/mingw/lib/../lib/:/usr/lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64                                                                                                                                                             -w64-mingw32/lib/:/usr/x86_64-w64-mingw32/sys-root/mingw/lib/
COLLECT_GCC_OPTIONS='-o' 'dd.exe' '-v' '-shared-libgcc' '-mtune=generic' '-   march                                                                                                                                                                =x86-64'
 /usr/lib/gcc/x86_64-w64-mingw32/4.9.2/collect2.exe -plugin      /usr/lib/gcc/x86_64-                                                                                                                                                                 w64-mingw32/4.9.2/cyglto_plugin.dll -plugin-opt=/usr/lib/gcc/x86_64-w64-mingw32/                                                                                                                                                                4.9.2/lto-wrapper.exe -plugin-opt=-fresolution=/tmp/ccaaJ5U7.res -plugin-opt=-pa                                                                                                                                                              ss-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through                                                                                                                                                              =-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex                                                                                                                                                               -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-ladvapi32 -plugin-                                                                                                                                                              opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass                                                                                                                                                              -through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-throug                                                                                                                                                              h=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -                                                                                                                                                              plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt --sysroot=                                                                                                                                                              /usr/x86_64-w64-mingw32/sys-root -m i386pep -Bdynamic -o dd.exe /usr/x86_64-w64-                                                                                                                                                              mingw32/sys-root/mingw/lib/../lib/crt2.o /usr/x86_64-w64-mingw32/sys-root/mingw/                                                                                                                                                              lib/../lib/crtbegin.o -L/usr/lib/gcc/x86_64-w64-mingw32/4.9.2 -L/usr/lib/gcc/x86                                                                                                                                                              _64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/lib/../lib -L/usr/x86_64-w6                                                                                                                                                              4-mingw32/sys-root/mingw/lib/../lib -L/usr/lib/gcc/x86_64-w64-mingw32/4.9.2/../.                                                                                                                                                                ./../../x86_64-w64-mingw32/lib -L/usr/x86_64-w64-mingw32/sys-root/mingw/lib /tmp                                                                                                                                                              /ccSHmwxw.o -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladv                                                                                                                                                              api32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex                                                                                                                                                               -lmsvcrt /usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib/default-manifest.o /                                                                                                                                                              usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib/crtend.o

EDIT: Did some more testing. When I made a program more complex than hello world (I used a #include ) the i686 version of the executable failed as it was missing some GCC related dll. When I add -static-libgcc -static-libstdc++, both version of the compilers work.

This leads me to conclude stuffs messed up with my linkers and DLLs. I don't know too much about this :(

Community
  • 1
  • 1
mp0295
  • 11
  • 3
  • Is there a DLL dependency that isn't being found? http://www.dependencywalker.com/ might help you find out. – Michael Burr May 22 '15 at 00:57
  • I used dependency walker. I will have to take some time to figure out what I'm looking at/for, but it immediately spit out these two errors: 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. – mp0295 May 22 '15 at 05:29
  • Looking some more. Most of the things listed in Module have x64 listed under CPU. LIBGCC_S_DW2-1.dll and LIBSTDC++6.dll are listed in red as x86. Is this bad? – mp0295 May 22 '15 at 05:36
  • Yeah, that seems bad. A 64-bit application can only use 64-bit DLLs. I don't use the Cygwin-based MinGW, I use nuwen (which will only build 64-bit apps and doesn't seem to have any DLL dependencies other than those provided by the Windows system) and the TDM distribution which will build 32 and 64-bit binaries and has both 32-bit and 64-bit DLLs. However the 64-bit DLLs have a "64" in the names, so either the MinGW you're using uses a different naming convention, or you are linking to the wrong libraries when building for 64-bit. Or a bad path. Or a combination. Or something. – Michael Burr May 22 '15 at 06:23
  • 1
    So I sorta solved it. From DW I found that for those two x86 DDLs (LIBSTDC++-6 and LIBGCC_S-DW2-1) the executable was looking in C:\mingw\bin instead of C:\cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\bin. So basically I had a 32bit minGW installation installed separately and my executable was getting 32-bit versions of those DLLs from the 32-bit minGW installation instead of the 64bit minGW install inside of cygwin. I dunno why this is happening, some environmental variable idk. To solve it for now I copied the correct DDLs into the folder the executable is in and it works. Thanks a ton. – mp0295 May 22 '15 at 07:18

0 Answers0