Why don't programs compiled with 64-bit MinGW g++ work on my 64-bit PC? - gcc

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 :(

Related

Msys gcc produces exe that results in "cannot execute binary file: Exec format error"

On an Msys installation I use only occasionally, I could not produce a working executable with gcc. I upgraded the system with pacman -Suy but the error persists.
Here is a session transcript:
$ gcc -v array-indexing.c -o array-indexing.exe
gcc -v array-indexing.c -o array-indexing.exe
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-msys/10.2.0/lto-wrapper.exe
Target: x86_64-pc-msys
Configured with: /c/_/S/gcc/src/gcc-10.2.0/configure --build=x86_64-pc-msys --prefix=/usr --libexecdir=/usr/lib --enable-bootstrap --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --with-arch=x86-64 --with-tune=generic --disable-multilib --enable-__cxa_atexit --with-dwarf2 --enable-languages=c,c++,fortran,lto --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-support --disable-libssp --disable-win32-registry --disable-symvers --with-gnu-ld --with-gnu-as --disable-isl-version-check --enable-checking=release --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible --enable-libstdcxx-filesystem-ts
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-o' 'array-indexing.exe' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-pc-msys/10.2.0/cc1.exe -quiet -v -idirafter /usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../lib/../include/w32api -idirafter /usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/lib/../lib/../../include/w32api array-indexing.c -quiet -dumpbase array-indexing.c -mtune=generic -march=x86-64 -auxbase array-indexing -version -o /tmp/ccHxGOyu.s
GNU C17 (GCC) version 10.2.0 (x86_64-pc-msys)
compiled by GNU C version 10.2.0, GMP version 6.2.0, MPFR version 4.1.0, MPC version 1.1.0, isl version isl-0.22.1-GMP
warning: GMP header version 6.2.0 differs from library version 6.2.1.
warning: MPC header version 1.1.0 differs from library version 1.2.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/include"
ignoring duplicate directory "/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/lib/../lib/../../include/w32api"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-pc-msys/10.2.0/include
/usr/lib/gcc/x86_64-pc-msys/10.2.0/include-fixed
/usr/include
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../lib/../include/w32api
End of search list.
GNU C17 (GCC) version 10.2.0 (x86_64-pc-msys)
compiled by GNU C version 10.2.0, GMP version 6.2.0, MPFR version 4.1.0, MPC version 1.1.0, isl version isl-0.22.1-GMP
warning: GMP header version 6.2.0 differs from library version 6.2.1.
warning: MPC header version 1.1.0 differs from library version 1.2.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 5dc831ba8ba50cc9f8b7e3207bc4f700
COLLECT_GCC_OPTIONS='-v' '-o' 'array-indexing.exe' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/as.exe -v -o /tmp/ccyivrKf.o /tmp/ccHxGOyu.s
GNU assembler version 2.36.1 (x86_64-pc-msys) using BFD version (GNU Binutils) 2.36.1
COMPILER_PATH=/usr/lib/gcc/x86_64-pc-msys/10.2.0/:/usr/lib/gcc/x86_64-pc-msys/10.2.0/:/usr/lib/gcc/x86_64-pc-msys/:/usr/lib/gcc/x86_64-pc-msys/10.2.0/:/usr/lib/gcc/x86_64-pc-msys/:/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/
LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-msys/10.2.0/:/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/lib/../lib/:/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/lib/:/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'array-indexing.exe' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-pc-msys/10.2.0/collect2.exe -plugin /usr/lib/gcc/x86_64-pc-msys/10.2.0/msys-lto_plugin.dll -plugin-opt=/usr/lib/gcc/x86_64-pc-msys/10.2.0/lto-wrapper.exe -plugin-opt=-fresolution=/tmp/cc7hM2x2.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmsys-2.0 -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id -m i386pep --wrap _Znwm --wrap _Znam --wrap _ZdlPv --wrap _ZdaPv --wrap _ZnwmRKSt9nothrow_t --wrap _ZnamRKSt9nothrow_t --wrap _ZdlPvRKSt9nothrow_t --wrap _ZdaPvRKSt9nothrow_t -Bdynamic --dll-search-prefix=msys- --tsaware -o array-indexing.exe /usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../lib/crt0.o /usr/lib/gcc/x86_64-pc-msys/10.2.0/crtbegin.o -L/usr/lib/gcc/x86_64-pc-msys/10.2.0 -L/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/lib/../lib -L/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/lib -L/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../.. /tmp/ccyivrKf.o -lgcc_s -lgcc -lmsys-2.0 -ladvapi32 -lshell32 -luser32 -lkernel32 -lgcc_s -lgcc /usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../lib/default-manifest.o /usr/lib/gcc/x86_64-pc-msys/10.2.0/crtend.o
COLLECT_GCC_OPTIONS='-v' '-o' 'array-indexing.exe' '-mtune=generic' '-march=x86-64'
$ file array-indexing.exe
file array-indexing.exe
array-indexing.exe: PE32+ executable (console) x86-64, for MS Windows
$ ./array-indexing.exe
./array-indexing.exe
bash: ./array-indexing.exe: cannot execute binary file: Exec format error
$
I'm at a loss. To my admittedly non-expert eye, the output looks inconspicuous. In particular, the generated file is recognized as a Windows executable.
The only thing standing out are these two warnings:
warning: GMP header version 6.2.0 differs from library version 6.2.1.
warning: MPC header version 1.1.0 differs from library version 1.2.1.
Googling didn't produce much insight — there was a broken dwarf5 a year ago, but the transcript shows it's using dwarf2, and that was about it.
Any ideas?
It's probably as ssbssa said in a comment: The compiler produced dwarf5 output which the runtime could not handle. The executable ran when stripped of debug information.
The issue was compounded because for some reason even repeated pacman -Suy didn't upgrade gcc or the binutils (I hadn't checked and thought that 10.2.0 was the latest available msys gcc version). Even though that command didn't output any error messages, it didn't upgrade non-core packages. It is possible that some msys processes still lingered and prevented upgrading non-core package upgrades, even though the installation closed the mintty console I was upgrading from.
For some reason the upgrades worked when I followed the advice on this page. I issued the command pacman --needed -S bash pacman pacman-mirrors msys2-runtime, followed by pacman -Suu, and a lot of package upgrades were performed successfully, resulting in a working toolchain.

Linking error in gfortran with devtoolset-6

I have system with CentOS 6.4 and it comes with GNU Fortran (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18).
I am doing quadrupule precision calculation and for that I installed devtoolset-6 w/o a problem. Since the system has a default gcc/gfortran installed, i cleared the shell with
env -i bash
and following that i set the devtoolset-6 environment
scl enable devtoolset-6 bash
If i check the installed gcc and gfortran version, they are as following
gcc (GCC) 6.3.1 20170216 (Red Hat 6.3.1-3)
GNU Fortran (GCC) 6.3.1 20170216 (Red Hat 6.3.1-3)
so far so good. I also have a testing example given below
implicit double precision(a-h,o-z)
print * , ' i:'
read(5,*) i
if(i.le.0) stop
a=i
b=sqrt(a)
print * , b
c=b*b
print * , c
end
compiled with
gfortran -fdefault-real-8 -o test.exe test.F
When i try to compile i am getting the following error
(.text+0x20): undefined reference to main'
/tmp/cc7n6vIv.o: In functionljacoeff_':test.F:(.text+0xf0): undefined reference to _gfortran_transfer_real128_write'
test.F:(.text+0x16b): undefined reference to_gfortran_transfer_complex128_write'
test.F:(.text+0x1ea): undefined reference to `_gfortran_transfer_complex128_write'
collect2: error: ld returned 1 exit status
At first, i thought the _gfortran_transfer_real128_write function is not defined and checked the library comes with devtoolset-6 using default "nm" command and indeed that function is defined in libgfortran.a. After some debugging and more debugging i discovered the "-v" option and recompiled the code, then noticed something confusing looks like ld checks the system old libraries instead of the one comes with devtoolset-6. The LIBRARY_PATH includes the /usr/lib/../lib64/ folder and that causes the error. In any case, If the linker couldn't find these function, it should also check the devtoolset-6 libraries. Looks like this doesn't happen. How could i resolve this linking error?
Driving: gfortran -v -fdefault-real-8 -o test.exe test.F -l gfortran
-l m -shared-libgcc Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/lto-wrapper
Target: x86_64-redhat-linux Configured with: ../configure
--enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-6/root/usr --mandir=/opt/rh/devtoolset-6/root/usr/share/man --infodir=/opt/rh/devtoolset-6/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --disable-libgcj --with-default-libstdcxx-abi=gcc4-compatible --with-isl=/builddir/build/BUILD/gcc-6.3.1-20170216/obj-x86_64-redhat-linux/isl-install
--enable-libmpx --with-mpc=/builddir/build/BUILD/gcc-6.3.1-20170216/obj-x86_64-redhat-linux/mpc-install
--with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 6.3.1 20170216 (Red Hat 6.3.1-3) (GCC)
COLLECT_GCC_OPTIONS='-v' '-fdefault-real-8' '-o' 'test.exe'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/f951
test.F -ffixed-form -cpp=/tmp/ccjQiTpi.f90 -quiet -v test.F -quiet
-dumpbase test.F -mtune=generic -march=x86-64 -auxbase test -version -fdefault-real-8 -fintrinsic-modules-path /opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/finclude
-o /tmp/cceJeO1o.s GNU Fortran (GCC) version 6.3.1 20170216 (Red Hat 6.3.1-3) (x86_64-redhat-linux) compiled by GNU C version 6.3.1 20170216 (Red Hat 6.3.1-3), GMP version 4.3.1, MPFR version 2.4.1, MPC
version 0.8.1, isl version 0.14 or 0.13 GGC heuristics: --param
ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring
nonexistent directory
"/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/include-fixed"
ignoring nonexistent directory
"/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here: /opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/finclude
/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/include
/usr/local/include /opt/rh/devtoolset-6/root/usr/include
/usr/include End of search list. GNU Fortran2008 (GCC) version 6.3.1
20170216 (Red Hat 6.3.1-3) (x86_64-redhat-linux) compiled by GNU C
version 6.3.1 20170216 (Red Hat 6.3.1-3), GMP version 4.3.1, MPFR
version 2.4.1, MPC version 0.8.1, isl version 0.14 or 0.13 GGC
heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-v' '-fdefault-real-8' '-o' 'test.exe'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/as
-v --64 -o /tmp/cc7n6vIv.o /tmp/cceJeO1o.s GNU assembler version 2.27 (x86_64-redhat-linux) using BFD version version 2.27-8.el6 Reading
specs from
/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/libgfortran.spec
rename spec lib to liborig COLLECT_GCC_OPTIONS='-v' '-fdefault-real-8'
'-o' 'test.exe' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
COMPILER_PATH=/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/:/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/:/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/:/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/:/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/:/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:
/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-fdefault-real-8' '-o' 'test.exe'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/collect2
-plugin /opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/liblto_plugin.so
-plugin-opt=/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccQAAlqC.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lquadmath -plugin-opt=-pass-through=-lm -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o test.exe /usr/lib/../lib64/crt1.o
/usr/lib/../lib64/crti.o
/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/crtbegin.o
-L/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1 -L/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../../lib64
-L/lib/../lib64 -L/usr/lib/../lib64 -L/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../..
/tmp/cc7n6vIv.o -lgfortran -lm -lgcc_s -lgcc -lquadmath -lm -lgcc_s
-lgcc -lc -lgcc_s -lgcc /opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/crtend.o
/usr/lib/../lib64/crtn.o /usr/lib/../lib64/crt1.o: In function
_start': (.text+0x20): undefined reference tomain' /tmp/cc7n6vIv.o:
In function ljacoeff_': test.F:(.text+0xf0): undefined reference to
_gfortran_transfer_real128_write' test.F:(.text+0x16b): undefined
reference to _gfortran_transfer_complex128_write'
test.F:(.text+0x1ea): undefined reference to
_gfortran_transfer_complex128_write' collect2: error: ld returned 1
exit status

Compilation program with libftd2xx library on ARM platform

I try to compile program in C, dedicated for FTDI chip. My enviroment is Advanced Tomato based Asus router + 16GB USB mem stick, mounted as /opt. Additionaly I have compiler + dependences + the newest FTDI library for ARMv7 from FTDI web site.
My compilation command is:
gcc -v -Wl,-rpath=/opt/usr/local/lib -Wl,--dynamic-linker=/opt/lib/ld-linux.so.3 -L/opt/usr/local/lib -O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -mfloat-abi=soft -l ftd2xx arco.c -o arco
Library patch is:
LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:/opt/lib:/opt/usr/lib:/opt/include:/opt/usr/local/lib:/opt/usr/include
Below verbose output from compilation process. Strange think is that in the first part of compilation, location od dynamic linker is correct, that is:
/opt/lib/ld-linux.so.3
But in the second part is wrong, that is:
/lib/ld-linux.so.3
It is not possible to copy/link ld-linux.so.3 to /lib because it is read only filesystem.
All this cause that when I run program, an library error occurs:
./arco: error while loading shared libraries: /opt/usr/local/lib/libftd2xx.so: internal error
Any idea what I am doing wrong?
Compilation output:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/lto-wrapper
Target: arm-openwrt-linux-gnueabi
Configured with: /media/ware3/Entware-ng.2016.08/build_dir/target-arm_cortex-a9_glibc-2.23_eabi/gcc-5.4.0/configure --target=arm-openwrt-linux --host=arm-openwrt-linux --build=x86_64-linux-gnu --program-prefix= --program-suffix= --prefix=/opt --exec-prefix=/opt --bindir=/opt/bin --sbindir=/opt/sbin --libexecdir=/opt/lib --sysconfdir=/opt/etc --datadir=/opt/share --localstatedir=/opt/var --mandir=/opt/man --infodir=/opt/info --disable-nls --build=x86_64-linux-gnu --host=arm-openwrt-linux-gnueabi --target=arm-openwrt-linux-gnueabi --enable-languages=c,c++ --with-bugurl=https://dev.openwrt.org/ --with-pkgversion='OpenWrt GCC 5.4.0' --enable-shared --enable-__cxa_atexit --with-default-libstdcxx-abi=gcc4-compatible --enable-target-optspace --with-gnu-ld --with-stage1-ldflags='-Wl,-rpath=/opt/lib -Wl,--dynamic-linker=/opt/lib/ld-linux.so.3' --with-boot-ldflags='static-libstdc++ -static-libgcc -Wl,-rpath=/opt/lib -Wl,--dynamic-linker=/opt/lib/ld-linux.so.3' --disable-nls --disable-libsanitizer --disable-libvtv --disable-libcilkrts --disable-libmudflap --disable-multilib --disable-libgomp --disable-libquadmath --disable-libssp --disable-decimal-float --disable-libstdcxx-pch --with-host-libstdcxx=-lstdc++ --prefix=/opt --libexecdir=/opt/lib --with-local-prefix=/opt --with-float=soft --with-default-libstdcxx-abi=gcc4-compatible
Thread model: posix
gcc version 5.4.0 (OpenWrt GCC 5.4.0)
COLLECT_GCC_OPTIONS='-v' '-L/opt/usr/local/lib' '-O2' '-pipe' '-march=armv7-a' '-mtune=cortex-a9' '-fno-caller-saves' '-mfloat-abi=soft' '-o' 'arco' '-mtls-dialect=gnu'
/opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/cc1 -quiet -v -imultilib . -imultiarch arm-linux-gnueabi arco.c -quiet -dumpbase arco.c -march=armv7-a -mtune=cortex-a9 -mfloat-abi=soft -mtls-dialect=gnu -auxbase arco -O2 -version -fno-caller-saves -o - |
as -v -march=armv7-a -mfloat-abi=soft -meabi=5 -o /opt/tmp/ccMeNAyM.o
GNU assembler version 2.26.1 (arm-openwrt-linux-gnueabi) using BFD version (GNU Binutils) 2.26.1
GNU C11 (OpenWrt GCC 5.4.0) version 5.4.0 (arm-openwrt-linux-gnueabi)
compiled by GNU C version 5.4.0, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=31954
ignoring nonexistent directory "/opt/include/arm-linux-gnueabi"
ignoring nonexistent directory "/opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/../../../../arm-openwrt-linux-gnueabi/include"
ignoring nonexistent directory "/usr/include/arm-linux-gnueabi"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/include
/opt/include
/opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/include-fixed
End of search list.
GNU C11 (OpenWrt GCC 5.4.0) version 5.4.0 (arm-openwrt-linux-gnueabi)
compiled by GNU C version 5.4.0, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=31954
Compiler executable checksum: a589712d81e28a1300ccb0e03d994135
COMPILER_PATH=/opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/:/opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/:/opt/lib/gcc/arm-openwrt-linux-gnueabi/:/opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/:/opt/lib/gcc/arm-openwrt-linux-gnueabi/
LIBRARY_PATH=/opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/:/opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-L/opt/usr/local/lib' '-O2' '-pipe' '-march=armv7-a' '-mtune=cortex-a9' '-fno-caller-saves' '-mfloat-abi=soft' '-o' 'arco' '-mtls-dialect=gnu'
/opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/collect2 -plugin /opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/liblto_plugin.so -plugin-opt=/opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/lto-wrapper -plugin-opt=-fresolution=/opt/tmp/ccOsGCvJ.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --eh-frame-hdr -dynamic-linker /lib/ld-linux.so.3 -X -m armelf_linux_eabi -o arco /opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/crt1.o /opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/crti.o /opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/crtbegin.o -L/opt/usr/local/lib -L/opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0 -L/opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/../../.. -rpath=/opt/usr/local/lib --dynamic-linker=/opt/lib/ld-linux.so.3 -lftd2xx /opt/tmp/ccMeNAyM.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/crtend.o /opt/lib/gcc/arm-openwrt-linux-gnueabi/5.4.0/crtn.o

How to compile with gcc inside OpenWRT

I have a "Linksys WRT1200AC" router running "OpenWrt Chaos Calmer 15.05.1" (mvebu Architecture) with "gcc_4.8.3-1_mvebu.ipk" and all other required packages installed.
I've tried to compile a C source file (something easy, similar to "hello world") with the command:
#gcc mysource.c -o myprogram
#chmod +x myprogram
#./myprogram
myprogram: line 1: syntax error: unexpected word (expecting ")")
The compiler gives me no errors or warnings, but the program can't be started.
It's like installing a .ipk package from a different arch to the router.
So I think that gcc is compiling my source for a different CPU/Arch.
The router cpu is: "Marvell Armada 38X dual-core # 1.33 GHz (88F6820-A0 C133)"
# uname -a
Linux OW 3.18.23 #1 SMP Sun Jan 31 12:53:24 CET 2016 armv7l GNU/Linux
# grep 'model name' /proc/cpuinfo
model name : ARMv7 Processor rev 1 (v7l)
model name : ARMv7 Processor rev 1 (v7l)
What is the correct command line to compile my sources inside openwrt with the right CPU/Arch option?
I've tried with different "-march/-mcpu" but no success.
This is with verbose on:
# gcc -v mysource.c -o myprogram
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/lto-wrapper
Target: arm-openwrt-linux-uclibcgnueabi
Configured with: /home/buildbot/slave-local/mvebu_generic/build/build_dir/target-arm_cortex-a9+vfpv3_uClibc-0.9.33.2_eabi/gcc-4.8.3/configure --target=arm-openwrt-linux --host=arm-openwrt-linux --build=x86_64-linux-gnu --program-prefix= --program-suffix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls --build=x86_64-linux-gnu --host=arm-openwrt-linux-uclibcgnueabi --target=arm-openwrt-linux-uclibcgnueabi --enable-languages=c,c++ --with-bugurl=https://dev.openwrt.org/ --with-pkgversion='OpenWrt GCC 4.8.3' --enable-shared --disable-__cxa_atexit --enable-target-optspace --with-gnu-ld --disable-nls --disable-libmudflap --disable-multilib --disable-libgomp --disable-libquadmath --disable-libssp --disable-decimal-float --disable-libstdcxx-pch --with-host-libstdcxx=-lstdc++ --prefix=/usr --libexecdir=/usr/lib --with-float=soft
Thread model: posix
gcc version 4.8.3 (OpenWrt GCC 4.8.3)
COLLECT_GCC_OPTIONS='-v' '-o' 'myprogram' '-mfloat-abi=soft' '-mtls-dialect=gnu'
/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/cc1 -quiet -v -imultilib . -imultiarch arm-linux-gnueabi mysource.c -quiet -dumpbase myprogram.c -mfloat-abi=soft -mtls-dialect=gnu -auxbase mysource -version -o /tmp/ccojawQz.s
GNU C (OpenWrt GCC 4.8.3) version 4.8.3 (arm-openwrt-linux-uclibcgnueabi)
compiled by GNU C version 4.8.3, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
ignoring nonexistent directory "/usr/local/include/arm-linux-gnueabi"
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/../../../../arm-openwrt-linux-uclibcgnueabi/include"
ignoring nonexistent directory "/usr/include/arm-linux-gnueabi"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/include
/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/include-fixed
/usr/include
End of search list.
GNU C (OpenWrt GCC 4.8.3) version 4.8.3 (arm-openwrt-linux-uclibcgnueabi)
compiled by GNU C version 4.8.3, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Well, seems that is working this way ;)
gcc -mabi=aapcs-linux mysource.c -o myprogram

Creating statically linked executable using GCC

I am creating the Embedded Mono Archive for one of my application. As per this link I need to create c/c++ executable which will instantiate appropriate framework and will load my managed assembly into it.
I tried creating the statically linked executable by specifying -static in g++ commandline but did not worked. below is verbose output from my g++ command -
$>g++ -Wall -o monolauncherstatic.out MonoLauncher.cpp `pkg-config --cflags --libs mono-2` -v -static
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i586-suse-linux/4.7/lto-wrapper
Target: i586-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --libexecdir=/usr/lib --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.7 --enable-ssp --disable-libssp --disable-libitm --disable-plugin --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --enable-linker-build-id --program-suffix=-4.7 --enable-linux-futex --without-system-libunwind --with-arch-32=i586 --with-tune=generic --build=i586-suse-linux
Thread model: posix
gcc version 4.7.2 20130108 [gcc-4_7-branch revision 195012] (SUSE Linux)
COLLECT_GCC_OPTIONS='-Wall' '-o' 'monolauncherstatic.out' '-D' '_REENTRANT' '-I' '/usr/lib/pkgconfig/../../include/mono-2.0' '-L/usr/lib/pkgconfig/../../lib' '-v' '-static' '-mtune=generic' '-march=i586'
/usr/lib/gcc/i586-suse-linux/4.7/cc1plus -quiet -v -I /usr/lib/pkgconfig/../../include/mono-2.0 -D_GNU_SOURCE -D _REENTRANT MonoLauncher.cpp -quiet -dumpbase MonoLauncher.cpp -mtune=generic -march=i586 -auxbase MonoLauncher -Wall -version -o /tmp/cc9htj2d.s
GNU C++ (SUSE Linux) version 4.7.2 20130108 [gcc-4_7-branch revision 195012] (i586-suse-linux)
compiled by GNU C version 4.7.2 20130108 [gcc-4_7-branch revision 195012], GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/pkgconfig/../../include/mono-2.0
/usr/include/c++/4.7
/usr/include/c++/4.7/i586-suse-linux
/usr/include/c++/4.7/backward
/usr/lib/gcc/i586-suse-linux/4.7/include
/usr/local/include
/usr/lib/gcc/i586-suse-linux/4.7/include-fixed
/usr/lib/gcc/i586-suse-linux/4.7/../../../../i586-suse-linux/include
/usr/include
End of search list.
GNU C++ (SUSE Linux) version 4.7.2 20130108 [gcc-4_7-branch revision 195012] (i586-suse-linux)
compiled by GNU C version 4.7.2 20130108 [gcc-4_7-branch revision 195012], GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 909fa5113dc6c530ae791996b13c020f
COLLECT_GCC_OPTIONS='-Wall' '-o' 'monolauncherstatic.out' '-D' '_REENTRANT' '-I' '/usr/lib/pkgconfig/../../include/mono-2.0' '-L/usr/lib/pkgconfig/../../lib' '-v' '-static' '-mtune=generic' '-march=i586'
/usr/lib/gcc/i586-suse-linux/4.7/../../../../i586-suse-linux/bin/as -v -I /usr/lib/pkgconfig/../../include/mono-2.0 --32 -o /tmp/ccwER6Jm.o /tmp/cc9htj2d.s
GNU assembler version 2.23.1 (i586-suse-linux) using BFD version (GNU Binutils; openSUSE 12.3) 2.23.1
COMPILER_PATH=/usr/lib/gcc/i586-suse-linux/4.7/:/usr/lib/gcc/i586-suse-linux/4.7/:/usr/lib/gcc/i586-suse-linux/:/usr/lib/gcc/i586-suse-linux/4.7/:/usr/lib/gcc/i586-suse-linux/:/usr/lib/gcc/i586-suse-linux/4.7/../../../../i586-suse-linux/bin/
LIBRARY_PATH=/usr/lib/gcc/i586-suse-linux/4.7/:/usr/lib/gcc/i586-suse-linux/4.7/../../../../i586-suse-linux/lib/:/usr/lib/gcc/i586-suse-linux/4.7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-Wall' '-o' 'monolauncherstatic.out' '-D' '_REENTRANT' '-I' '/usr/lib/pkgconfig/../../include/mono-2.0' '-L/usr/lib/pkgconfig/../../lib' '-v' '-static' '-mtune=generic' '-march=i586'
/usr/lib/gcc/i586-suse-linux/4.7/collect2 --build-id -m elf_i386 -static -o monolauncherstatic.out /usr/lib/gcc/i586-suse-linux/4.7/../../../crt1.o /usr/lib/gcc/i586-suse-linux/4.7/../../../crti.o /usr/lib/gcc/i586-suse-linux/4.7/crtbeginT.o -L/usr/lib/pkgconfig/../../lib -L/usr/lib/gcc/i586-suse-linux/4.7 -L/usr/lib/gcc/i586-suse-linux/4.7/../../../../i586-suse-linux/lib -L/usr/lib/gcc/i586-suse-linux/4.7/../../.. /tmp/ccwER6Jm.o -lmono-2.0 -lrt -ldl -lpthread -lstdc++ -lm --start-group -lgcc -lgcc_eh -lc --end-group /usr/lib/gcc/i586-suse-linux/4.7/crtend.o /usr/lib/gcc/i586-suse-linux/4.7/../../../crtn.o
/usr/lib/gcc/i586-suse-linux/4.7/../../../../i586-suse-linux/bin/ld: cannot find -lrt
/usr/lib/gcc/i586-suse-linux/4.7/../../../../i586-suse-linux/bin/ld: cannot find -ldl
/usr/lib/gcc/i586-suse-linux/4.7/../../../../i586-suse-linux/bin/ld: cannot find -lpthread
/usr/lib/gcc/i586-suse-linux/4.7/../../../../i586-suse-linux/bin/ld: cannot find -lm
/usr/lib/gcc/i586-suse-linux/4.7/../../../../i586-suse-linux/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
I also tried pkg-config --cflags --libs mono-2
It seems you don't have static libraries installed, e.g. libc.a, libm.a, libpthread.a, etc.
If you're using SuSE, perhaps yum install glibc-devel-static will work. Maybe some of the other libraries will need other packages to be installed.

Resources