Cross-compiling x86 shared library to ARM architecture - c

I have been trying to cross compile x86 GNU scientific library to ARM architecture for execution on my Cyclone V FPGA, after getting errors regarding libgsl.so: File format not recognised. I have went to the gsl-2.4 directory, and ran ./configure --build=x86_64-pc-linux-gnu --host=arm-linux-gnueabi --prefix=/usr/local/arm-linux this seems to work, and create makefiles:
checking build system type... x86_64-pc-linux-gnu
checking host system type... arm-unknown-linux-gnueabi
checking for arm-linux-gnueabi-gcc... arm-linux-gnueabi-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
...
...
config.status: creating utils/Makefile
config.status: creating vector/Makefile
config.status: creating wavelet/Makefile
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
However, when I then run make after some time the command halts with the following error:
.libs/sasum.o: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
Makefile:679: recipe for target 'libgslcblas.la' failed
make[2]: *** [libgslcblas.la] Error 1
make[2]: Leaving directory '/home/gsl-2.4/cblas'
Makefile:961: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/gsl-2.4'
Makefile:663: recipe for target 'all' failed
make: *** [all] Error 2
I have tried using other tool chains like arm-linux-gnueabihf with similar results. Has anyone get any ideas on why these errors may be occuring, or just how I can finally get this GSL library compiled for ARM architectures!
Thanks in advance
https://pastebin.com/S5HSqmT6 : output from make CC:..
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabi/5/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-armel-cross/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-armel-cross --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-armel-cross --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libgcj --enable-objc-gc --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv5t --with-float=soft --disable-werror --enable-multilib --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabi --program-prefix=arm-linux-gnueabi- --includedir=/usr/arm-linux-gnueabi/include
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9)
COMPILER_PATH=/usr/lib/gcc-cross/arm-linux-gnueabi/5/:/usr/lib/gcc-cross/arm-linux-gnueabi/5/:/usr/lib/gcc-cross/arm-linux-gnueabi/:/usr/lib/gcc-cross/arm-linux-gnueabi/5/:/usr/lib/gcc-cross/arm-linux-gnueabi/:/usr/lib/gcc-cross/arm-linux-gnueabi/5/../../../../arm-linux-gnueabi/bin/
LIBRARY_PATH=/usr/lib/gcc-cross/arm-linux-gnueabi/5/:/usr/lib/gcc-cross/arm-linux-gnueabi/5/../../../../arm-linux-gnueabi/lib/../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc-cross/arm-linux-gnueabi/5/../../../../arm-linux-gnueabi/lib/:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-shared' '-fPIC' '-D' 'PIC' '-O2' '-o' '.libs/libgslcblas.so.0.0.0' '-v' '-march=armv5t' '-mfloat-abi=soft' '-mtls-dialect=gnu'
/usr/lib/gcc-cross/arm-linux-gnueabi/5/collect2 -plugin /usr/lib/gcc-cross/arm-linux-gnueabi/5/liblto_plugin.so -plugin-opt=/usr/lib/gcc-cross/arm-linux-gnueabi/5/lto-wrapper -plugin-opt=-fresolution=/tmp/ccdsl841.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 --sysroot=/ --build-id --eh-frame-hdr -shared -X --hash-style=gnu --as-needed -m armelf_linux_eabi -z relro -o .libs/libgslcblas.so.0.0.0 /usr/lib/gcc-cross/arm-linux-gnueabi/5/../../../../arm-linux-gnueabi/lib/../lib/crti.o /usr/lib/gcc-cross/arm-linux-gnueabi/5/crtbeginS.o -L/usr/lib/gcc-cross/arm-linux-gnueabi/5 -L/usr/lib/gcc-cross/arm-linux-gnueabi/5/../../../../arm-linux-gnueabi/lib/../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc-cross/arm-linux-gnueabi/5/../../../../arm-linux-gnueabi/lib .libs/sasum.o .libs/saxpy.o .libs/scasum.o .libs/scnrm2.o .libs/scopy.o .libs/sdot.o .libs/sdsdot.o .libs/sgbmv.o .libs/sgemm.o .libs/sgemv.o .libs/sger.o .libs/snrm2.o .libs/srot.o .libs/srotg.o .libs/srotm.o .libs/srotmg.o .libs/ssbmv.o .libs/sscal.o .libs/sspmv.o .libs/sspr.o .libs/sspr2.o .libs/sswap.o .libs/ssymm.o .libs/ssymv.o .libs/ssyr.o .libs/ssyr2.o .libs/ssyr2k.o .libs/ssyrk.o .libs/stbmv.o .libs/stbsv.o .libs/stpmv.o .libs/stpsv.o .libs/strmm.o .libs/strmv.o .libs/strsm.o .libs/strsv.o .libs/dasum.o .libs/daxpy.o .libs/dcopy.o .libs/ddot.o .libs/dgbmv.o .libs/dgemm.o .libs/dgemv.o .libs/dger.o .libs/dnrm2.o .libs/drot.o .libs/drotg.o .libs/drotm.o .libs/drotmg.o .libs/dsbmv.o .libs/dscal.o .libs/dsdot.o .libs/dspmv.o .libs/dspr.o .libs/dspr2.o .libs/dswap.o .libs/dsymm.o .libs/dsymv.o .libs/dsyr.o .libs/dsyr2.o .libs/dsyr2k.o .libs/dsyrk.o .libs/dtbmv.o .libs/dtbsv.o .libs/dtpmv.o .libs/dtpsv.o .libs/dtrmm.o .libs/dtrmv.o .libs/dtrsm.o .libs/dtrsv.o .libs/dzasum.o .libs/dznrm2.o .libs/caxpy.o .libs/ccopy.o .libs/cdotc_sub.o .libs/cdotu_sub.o .libs/cgbmv.o .libs/cgemm.o .libs/cgemv.o .libs/cgerc.o .libs/cgeru.o .libs/chbmv.o .libs/chemm.o .libs/chemv.o .libs/cher.o .libs/cher2.o .libs/cher2k.o .libs/cherk.o .libs/chpmv.o .libs/chpr.o .libs/chpr2.o .libs/cscal.o .libs/csscal.o .libs/cswap.o .libs/csymm.o .libs/csyr2k.o .libs/csyrk.o .libs/ctbmv.o .libs/ctbsv.o .libs/ctpmv.o .libs/ctpsv.o .libs/ctrmm.o .libs/ctrmv.o .libs/ctrsm.o .libs/ctrsv.o .libs/zaxpy.o .libs/zcopy.o .libs/zdotc_sub.o .libs/zdotu_sub.o .libs/zdscal.o .libs/zgbmv.o .libs/zgemm.o .libs/zgemv.o .libs/zgerc.o .libs/zgeru.o .libs/zhbmv.o .libs/zhemm.o .libs/zhemv.o .libs/zher.o .libs/zher2.o .libs/zher2k.o .libs/zherk.o .libs/zhpmv.o .libs/zhpr.o .libs/zhpr2.o .libs/zscal.o .libs/zswap.o .libs/zsymm.o .libs/zsyr2k.o .libs/zsyrk.o .libs/ztbmv.o .libs/ztbsv.o .libs/ztpmv.o .libs/ztpsv.o .libs/ztrmm.o .libs/ztrmv.o .libs/ztrsm.o .libs/ztrsv.o .libs/icamax.o .libs/idamax.o .libs/isamax.o .libs/izamax.o .libs/xerbla.o -lm -soname libgslcblas.so.0 -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc-cross/arm-linux-gnueabi/5/crtendS.o /usr/lib/gcc-cross/arm-linux-gnueabi/5/../../../../arm-linux-gnueabi/lib/../lib/crtn.o
.libs/sasum.o: file not recognized: File format not recognised
collect2: error: ld returned 1 exit status
and then:
.libs/sasum.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

Related

Difference between gcc and ${CC}

Recently I got an NXP imx8 board. And I want to test my programme. But it didn't work on imx8.
When I use aarch64-poky-linux-gcc
$ source /opt/fsl-imx-internal-xwayland/5.15-kirkstone/environment-setup-armv8a-poky-linux
$ aarch64-poky-linux-gcc -o hello hello.c
In file included from hello.c:1:
/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/include/stdio.h:27:10: fatal error: bits/libc-header-start.h: No such file or directory
27 | #include <bits/libc-header-start.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
when I use ${CC}
$ source /opt/fsl-imx-internal-xwayland/5.15-kirkstone/environment-setup-armv8a-poky-linux
${CC} -o hello hello.c # it can work
So I want to know the reason.
And I do this thing:
$ echo 'main(){}'|aarch64-poky-linux-gcc -E -v -
Using built-in specs.
COLLECT_GCC=aarch64-poky-linux-gcc
Target: aarch64-poky-linux
Configured with: ../../../../../../work-shared/gcc-11.2.0-r0/gcc-11.2.0/configure --build=x86_64-linux --host=x86_64-pokysdk-linux --target=aarch64-poky-linux --prefix=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr --exec_prefix=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr --bindir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux --sbindir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux --libexecdir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/libexec/aarch64-poky-linux --datadir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/share --sysconfdir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/etc --sharedstatedir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/com --localstatedir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/var --libdir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux --includedir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/include --oldincludedir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/include --infodir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/share/info --mandir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/share/man --disable-silent-rules --disable-dependency-tracking --with-libtool-sysroot=/home/bamboo/build/5.15-kirkstone-full/fsl-imx-internal-xwayland/mx8m/yocto/build/tmp/work/x86_64-nativesdk-pokysdk-linux/gcc-cross-canadian-aarch64/11.2.0-r0/recipe-sysroot --with-gnu-ld --enable-shared --enable-languages=c,c++ --enable-threads=posix --enable-multilib --enable-default-pie --enable-c99 --enable-long-long --enable-symvers=gnu --enable-libstdcxx-pch --program-prefix=aarch64-poky-linux- --without-local-prefix --disable-install-libiberty --disable-libssp --enable-libitm --enable-lto --disable-bootstrap --with-system-zlib --with-linker-hash-style=gnu --enable-linker-build-id --with-ppl=no --with-cloog=no --enable-checking=release --enable-cheaders=c_global --without-isl --with-gxx-include-dir=/not/exist/usr/include/c++/11.2.0 --with-build-time-tools=/home/bamboo/build/5.15-kirkstone-full/fsl-imx-internal-xwayland/mx8m/yocto/build/tmp/work/x86_64-nativesdk-pokysdk-linux/gcc-cross-canadian-aarch64/11.2.0-r0/recipe-sysroot-native/usr/aarch64-poky-linux/bin --with-sysroot=/not/exist --with-build-sysroot=/home/bamboo/build/5.15-kirkstone-full/fsl-imx-internal-xwayland/mx8m/yocto/build/tmp/work/x86_64-nativesdk-pokysdk-linux/gcc-cross-canadian-aarch64/11.2.0-r0/recipe-sysroot --enable-standard-branch-protection --enable-poison-system-directories --disable-static --enable-nls --with-glibc-version=2.28 --enable-initfini-array --enable-__cxa_atexit
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC)
COLLECT_GCC_OPTIONS='-E' '-v' '-mlittle-endian' '-mabi=lp64'
/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/libexec/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/cc1 -E -quiet -v - -mlittle-endian -mabi=lp64 -dumpbase -
ignoring nonexistent directory "/not/exist/usr/lib/aarch64-poky-linux/11.2.0/include"
ignoring nonexistent directory "/not/exist/usr/local/include"
ignoring nonexistent directory "/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/../../../../../aarch64-poky-linux/include"
ignoring nonexistent directory "/not/exist/usr/include/"
#include "..." search starts here:
#include <...> search starts here:
/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/include
/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/include-fixed
End of search list.
# 0 "<stdin>"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "<stdin>"
main(){}
COMPILER_PATH=/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/libexec/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/:/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/libexec/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/:/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/libexec/aarch64-poky-linux/gcc/aarch64-poky-linux/:/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/:/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/gcc/aarch64-poky-linux/
LIBRARY_PATH=/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/
COLLECT_GCC_OPTIONS='-E' '-v' '-mlittle-endian' '-mabi=lp64'
$ echo 'main(){}'|${CC} -E -v -
Using built-in specs.
COLLECT_GCC=aarch64-poky-linux-gcc
Target: aarch64-poky-linux
Configured with: ../../../../../../work-shared/gcc-11.2.0-r0/gcc-11.2.0/configure --build=x86_64-linux --host=x86_64-pokysdk-linux --target=aarch64-poky-linux --prefix=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr --exec_prefix=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr --bindir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux --sbindir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux --libexecdir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/libexec/aarch64-poky-linux --datadir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/share --sysconfdir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/etc --sharedstatedir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/com --localstatedir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/var --libdir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux --includedir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/include --oldincludedir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/include --infodir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/share/info --mandir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/share/man --disable-silent-rules --disable-dependency-tracking --with-libtool-sysroot=/home/bamboo/build/5.15-kirkstone-full/fsl-imx-internal-xwayland/mx8m/yocto/build/tmp/work/x86_64-nativesdk-pokysdk-linux/gcc-cross-canadian-aarch64/11.2.0-r0/recipe-sysroot --with-gnu-ld --enable-shared --enable-languages=c,c++ --enable-threads=posix --enable-multilib --enable-default-pie --enable-c99 --enable-long-long --enable-symvers=gnu --enable-libstdcxx-pch --program-prefix=aarch64-poky-linux- --without-local-prefix --disable-install-libiberty --disable-libssp --enable-libitm --enable-lto --disable-bootstrap --with-system-zlib --with-linker-hash-style=gnu --enable-linker-build-id --with-ppl=no --with-cloog=no --enable-checking=release --enable-cheaders=c_global --without-isl --with-gxx-include-dir=/not/exist/usr/include/c++/11.2.0 --with-build-time-tools=/home/bamboo/build/5.15-kirkstone-full/fsl-imx-internal-xwayland/mx8m/yocto/build/tmp/work/x86_64-nativesdk-pokysdk-linux/gcc-cross-canadian-aarch64/11.2.0-r0/recipe-sysroot-native/usr/aarch64-poky-linux/bin --with-sysroot=/not/exist --with-build-sysroot=/home/bamboo/build/5.15-kirkstone-full/fsl-imx-internal-xwayland/mx8m/yocto/build/tmp/work/x86_64-nativesdk-pokysdk-linux/gcc-cross-canadian-aarch64/11.2.0-r0/recipe-sysroot --enable-standard-branch-protection --enable-poison-system-directories --disable-static --enable-nls --with-glibc-version=2.28 --enable-initfini-array --enable-__cxa_atexit
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC)
COLLECT_GCC_OPTIONS='-march=armv8-a+crc+crypto' '-fstack-protector-strong' '-O2' '-D' '_FORTIFY_SOURCE=2' '-Wformat=1' '-Wformat-security' '-Werror=format-security' '-E' '-v' '-mlittle-endian' '-mabi=lp64'
/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/libexec/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/cc1 -E -quiet -v -isysroot /opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/armv8a-poky-linux -D _FORTIFY_SOURCE=2 - -march=armv8-a+crc+crypto -mlittle-endian -mabi=lp64 -Wformat=1 -Wformat-security -Werror=format-security -fstack-protector-strong -O2 -dumpbase -
ignoring nonexistent directory "/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/armv8a-poky-linux/usr/local/include"
ignoring nonexistent directory "/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/../../../../../aarch64-poky-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/include
/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/armv8a-poky-linux/usr/lib/aarch64-poky-linux/11.2.0/include
/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/include-fixed
/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/armv8a-poky-linux/usr/include/
End of search list.
# 0 "<stdin>"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/armv8a-poky-linux/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "<stdin>"
main(){}
COMPILER_PATH=/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/libexec/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/:/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/libexec/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/:/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/libexec/aarch64-poky-linux/gcc/aarch64-poky-linux/:/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/:/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/gcc/aarch64-poky-linux/
LIBRARY_PATH=/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/gcc/aarch64-poky-linux/11.2.0/:/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/armv8a-poky-linux/lib/:/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/armv8a-poky-linux/usr/lib/aarch64-poky-linux/11.2.0/:/opt/fsl-imx-internal-xwayland/5.15-kirkstone/sysroots/armv8a-poky-linux/usr/lib/
COLLECT_GCC_OPTIONS='-march=armv8-a+crc+crypto' '-fstack-protector-strong' '-O2' '-D' '_FORTIFY_SOURCE=2' '-Wformat=1' '-Wformat-security' '-Werror=format-security' '-E' '-v' '-mlittle-endian' '-mabi=lp64'
I found that they both use aarch64-poky-linux-gcc. But I still don't know the difference between them.
gcc is the name of a command. Your shell will look for it in the path.
${CC} is a variable substitution. Your shell will look for it in the environment of the shell process.
gcc is the compiler of your machine. You can find which one and where is located like this:
readlink -f $(which gcc): this will show you the path of the program used
gcc --version: will show you the version of your gcc compiler
In case you are building in a PC, then the gcc will build programs for x86 architectures. In your case you need a compiler to generate programs for arm64 architectures (the opensource is aarch64-linux-gnu-gcc but the providers usually give you a modified toolchain with the compiler and all necessary libraries/headers.
When you crosscompile, you must "source" an environment file, this will modify the environment variables in the terminal were you sourced the environment file this will create the environment variable CC, this will contains the path to the compiler with some parameters for the compiler.
If you run echo ${CC} you will see the toolchain and the parameters.
The idea always is to have an isolated environment which doesn't depend on the OS, gcc version of the host PC, that's why you were provided with the compiler and you must use ${CC} to crosscompile to the architecture arm which is the base of imx SOCs

undefined reference to "readline" in c file on ubuntu 18.04 (libreadline-dev installed, linked with "-lreadline"

I'm aware that there are many threads about this on Stackoverflow but non of the solutions helped me. I'm using Ubuntu 18.04 with all the stuff that a dev typically needs: build-essential, libreadline-dev, ...
I had a look in /usr/include/readline but readline is definitely there!
gcc always tells me:
undefined reference to "readline"
This happens by the way independently if i'm linking with "-lreadline" or not.
Edit
As user #Kamil Cuk already provided the simple solution I'd like to add some more information:
$ gcc -lreadline -o code code.c
works on MacOS with apple-gcc (which uses clang) as well as with gnu-gcc (installed via brew). Only on Ubuntu the linker-flag has to be after "code.c"
(perhaps because Ubuntu uses gcc-7 and on my Mac I'm using gcc-8)
Edit end
code.c
#include <stdlib.h>
#include <stdio.h>
#include <readline/readline.h>
int main(void) {
char * buffer = readline("enter sth: ");
printf("%s\n", buffer);
printf("bye!\n");
}
libreadline-dev package info
dpkg -L libreadline-dev
/.
/usr
/usr/include
/usr/include/readline
/usr/include/readline/chardefs.h
/usr/include/readline/history.h
/usr/include/readline/keymaps.h
/usr/include/readline/readline.h
/usr/include/readline/rlconf.h
/usr/include/readline/rlstdc.h
/usr/include/readline/rltypedefs.h
/usr/include/readline/tilde.h
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libhistory.a
/usr/lib/x86_64-linux-gnu/libreadline.a
/usr/share
/usr/share/doc
/usr/share/info
/usr/lib/x86_64-linux-gnu/libhistory.so
/usr/lib/x86_64-linux-gnu/libreadline.so
/usr/share/doc/libreadline-dev
gcc command
$ gcc -L/usr/lib/x86_64-linux-gnu -lreadline -Wall -Werror -v -o code code.c
gcc err output
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.3.0-27ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04)
COLLECT_GCC_OPTIONS='-L/usr/lib/x86_64-linux-gnu' '-Wall' '-Werror' '-v' '-o' 'code' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/7/cc1 -quiet -v -imultiarch x86_64-linux-gnu code.c -quiet -dumpbase code.c -mtune=generic -march=x86-64 -auxbase code -Wall -Werror -version -fstack-protector-strong -Wformat-security -o /tmp/ccLBo26t.s
GNU C11 (Ubuntu 7.3.0-27ubuntu1~18.04) version 7.3.0 (x86_64-linux-gnu)
compiled by GNU C version 7.3.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/7/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C11 (Ubuntu 7.3.0-27ubuntu1~18.04) version 7.3.0 (x86_64-linux-gnu)
compiled by GNU C version 7.3.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: c8081a99abb72bbfd9129549110a350c
COLLECT_GCC_OPTIONS='-L/usr/lib/x86_64-linux-gnu' '-Wall' '-Werror' '-v' '-o' 'code' '-mtune=generic' '-march=x86-64'
as -v --64 -o /tmp/ccqaH7jD.o /tmp/ccLBo26t.s
Die GNU-Assembler-Version 2.30 (x86_64-linux-gnu) benutzt die BFD-Version (GNU Binutils for Ubuntu) 2.30
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-L/usr/lib/x86_64-linux-gnu' '-Wall' '-Werror' '-v' '-o' 'code' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/7/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/7/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper -plugin-opt=-fresolution=/tmp/ccYuIgyM.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 --sysroot=/ --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o code /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/7 -L/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/7/../../.. -lreadline /tmp/ccqaH7jD.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o
/tmp/ccqaH7jD.o: In Funktion »main«:
code.c:(.text+0x10): Warnung: undefinierter Verweis auf »readline«
collect2: error: ld returned 1 exit status
I tried several solutions provided on the internet, such as the following links but none of them worked:
How do I properly reference the GNU readline library to scan terminal input?
-L/usr/local/lib -I/usr/local/include
https://www.linuxquestions.org/questions/programming-9/undefined-reference-to-readline-494533/
#include "/usr/include/readline/readline.h"
does anyone have an idea?
(by the way, probably don't important: readline works on my Mac but not in my Ubuntu Virtual Machine)
gcc .... code.c .... -lreadline
From gcc link options:
-l library
-llibrary
...
It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded.

Error while compiling, collect2: cannot find ld

Could somebody have met this problem, I have collect2: cannot find 'ld' error when try:
gcc -v -pthread -I /tmp/usr/include -no-use-gold-linker /tmp/teeest.c -o /tmp/teeest > /tmp/ok.log 2>/tmp/error.log
Output:
Using built-in specs.
gcc: unrecognized option '-no-use-gold-linker'
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
COLLECT_GCC_OPTIONS='-v' '-pthread' '-I' '/tmp/usr/include' '-no-use-gold-linker' '-o' '/tmp/teeest' '-mtune=generic'
/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/cc1 -quiet -v -I /tmp/usr/include -iprefix ../lib/gcc/x86_64-redhat-linux/4.4.7/ -D_REENTRANT /tmp/teeest.c -quiet -dumpbase teeest.c -mtune=generic -auxbase teeest -version -o /tmp/ccVr6ozd.s
ignoring nonexistent directory "../lib/gcc/x86_64-redhat-linux/4.4.7/include"
ignoring nonexistent directory "../lib/gcc/x86_64-redhat-linux/4.4.7/include-fixed"
ignoring nonexistent directory "../lib/gcc/x86_64-redhat-linux/4.4.7/../../../../x86_64-redhat-linux/include"
ignoring nonexistent directory "../lib/../lib/gcc/x86_64-redhat-linux/4.4.7/include"
ignoring nonexistent directory "../lib/../lib/gcc/x86_64-redhat-linux/4.4.7/include-fixed"
ignoring nonexistent directory "../lib/../lib/gcc/x86_64-redhat-linux/4.4.7/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/tmp/usr/include
/usr/local/include
/usr/include
End of search list.
GNU C (GCC) version 4.4.7 20120313 (Red Hat 4.4.7-17) (x86_64-redhat-linux)
compiled by GNU C version 4.4.7 20120313 (Red Hat 4.4.7-17), GMP version 4.3.1, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: d2ae160e13b93f509f25a064aa53b455
COLLECT_GCC_OPTIONS='-v' '-pthread' '-I' '/tmp/usr/include' '-no-use-gold-linker' '-o' '/tmp/teeest' '-mtune=generic'
as -V -Qy -o /tmp/ccCIoBhH.o /tmp/ccVr6ozd.s
GNU assembler version 2.20.51.0.2 (x86_64-redhat-linux) using BFD version version 2.20.51.0.2-5.44.el6 20100205
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:../lib/../lib64/:/lib/../lib64/:/usr/lib/../lib64/:../lib/:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-pthread' '-I' '/tmp/usr/include' '-no-use-gold-linker' '-o' '/tmp/teeest' '-mtune=generic'
/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/collect2 --eh-frame-hdr --build-id -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o /tmp/teeest /usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7 -L../lib/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L../lib /tmp/ccCIoBhH.o -lgcc --as-needed -lgcc_s --no-as-needed -lpthread -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtend.o /usr/lib/../lib64/crtn.o
collect2: cannot find 'ld'
Check ld existing:
ld: /usr/bin/ld /usr/share/man/man1/ld.1.gz
Check $PATH
/usr/local/bin:/bin:/usr/bin
I try to compile hello world application on C in /tmp dir.
CentOS 6, 2016, 2.6.32-642.1.1.el6.x86_64, x86_64
PATH=$PATH; export PATH; gcc -v -pthread -I /tmp/usr/include /tmp/test.c -o /tmp/test > /tmp/ok.log 2>/tmp/error.log; #eto pizdez

GCJ Linking Error: Says error: undefined reference to 'main' collect2: error: ld returned 1 exit status

The code is this:
public class Thingy
{
public static void main(String[] args)
{
System.out.println(Math.random());
}
}
So, absolutely NOT an unusual case, just a basic example.
When I try to use GCJ's javac implementation to make bytecode instead of the OpenJDK one, it works fine.
neil#neil-Inspiron-M5030:~/javastuff$ javac Thingy.java
neil#neil-Inspiron-M5030:~/javastuff$ java Thingy
0.2794511843566371
But when I try to get GCJ to make native code, I get that linker error. If you want, I can give you the verbose output:
neil#neil-Inspiron-M5030:~/javastuff$ gcj --verbose Thingy.java
Using built-in specs.
Reading specs from /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcj.spec
rename spec startfile to startfileorig
rename spec lib to liborig
COLLECT_GCC=gcj
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.2-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcj-4.7/README.Bugs --enable-languages=c,c++,java --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.7/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.7 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.7 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-1ubuntu1)
COLLECT_GCC_OPTIONS='-fsaw-java-file' '-v' '-fbootclasspath=./:/usr/share/java/libgcj-4.7.jar' '-g1' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.7/ecj1 Thingy.java -g1 -fbootclasspath=./:/usr/share/java/libgcj-4.7.jar -g1 -fsource=1.5 -ftarget=1.5 -fzip-dependency /tmp/cckwg5AG.zip -fzip-target /tmp/ccbixA8G.jar
COLLECT_GCC_OPTIONS='-fsaw-java-file' '-v' '-fbootclasspath=./:/usr/share/java/libgcj-4.7.jar' '-g1' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.7/jc1 /tmp/ccbixA8G.jar -fsource-filename=Thingy.java -fhash-synchronization -fno-use-divide-subroutine -fuse-boehm-gc -fnon-call-exceptions -fkeep-inline-functions -quiet -dumpbase Thingy.java -mtune=generic -march=x86-64 -auxbase Thingy -g1 -version -fsaw-java-file -fbootclasspath=./:/usr/share/java/libgcj-4.7.jar -faux-classpath /tmp/cckwg5AG.zip -o /tmp/cclZeoeJ.s
GNU Java (Ubuntu/Linaro 4.7.2-1ubuntu1) version 4.7.2 (x86_64-linux-gnu)
compiled by GNU C version 4.7.2, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Java (Ubuntu/Linaro 4.7.2-1ubuntu1) version 4.7.2 (x86_64-linux-gnu)
compiled by GNU C version 4.7.2, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Class path starts here:
/tmp/cckwg5AG.zip/ (zip)
./ (system)
/usr/share/java/libgcj-4.7.jar/ (system) (zip)
COLLECT_GCC_OPTIONS='-fsaw-java-file' '-v' '-fbootclasspath=./:/usr/share/java/libgcj-4.7.jar' '-g1' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
as -v --64 -o /tmp/cczIy0oL.o /tmp/cclZeoeJ.s
GNU assembler version 2.22.90 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.22.90.20120924
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.7/:/usr/lib/gcc/x86_64-linux-gnu/4.7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.7/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.7/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-fsaw-java-file' '-v' '-fbootclasspath=./:/usr/share/java/libgcj-4.7.jar' '-g1' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.7/collect2 --sysroot=/ --build-id --no-add-needed --as-needed --eh-frame-hdr -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.7/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.7 -L/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.7/../../.. /tmp/cczIy0oL.o -lgcc_s -lgcc -lgcj -lm -lpthread -lrt -lz -ldl -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.7/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crtn.o
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o(.text+0x20): error: undefined reference to 'main'
collect2: error: ld returned 1 exit status
so, I suppose my question is, is does anyone have any idea what might have went wrong?
I guess you need to add --main=Thingy to the command. Since several classes may have a 'main' method, the linker needs to be told which one to use.
Also, you might want to add -o <name of executable>, otherwise, you'll get a 'a.out' file, which is the default executable name for the GNU compilers (and any C compiler actually).
Regards

Can't compile and link programs with clang

I recently compiled Clang 2.9 (from here) on an Ubuntu system. I'm having trouble compiling and linking a simple program. Does anyone know how to fix this? Here's the output I see:
a#ubuntu:~/Desktop$ clang add.c
/usr/bin/ld: 1: Syntax error: word unexpected (expecting ")")
clang: error: linker command failed with exit code 2 (use -v to see invocation)
uname -a output
Linux ubuntu 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 i686 i686 i386 GNU/Linux
gcc -v output:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.5.2-8ubuntu4 --with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.5 --enable-shared --enable-multiarch --with-multiarch-defaults=i386-linux-gnu --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib/i386-linux-gnu --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.5 --libdir=/usr/lib/i386-linux-gnu --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-gold --enable-ld=default --with-plugin-ld=ld.gold --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)
clang verbose ouput
clang version 2.9 (tags/RELEASE_29/final)
Target: i386-pc-linux-gnu
Thread model: posix
"/usr/local/bin/clang" -cc1 -triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name add.c -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu pentium4 -target-linker-version 2.21.0.20110327 -momit-leaf-frame-pointer -v -resource-dir /usr/local/bin/../lib/clang/2.9 -ferror-limit 19 -fmessage-length 138 -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/cc-JJruTv.o -x c add.c
clang -cc1 version 2.9 based upon llvm 2.9 hosted on i386-pc-linux-gnu
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/local/bin/../lib/clang/2.9/include
/usr/include
End of search list.
"/usr/bin/ld" --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o a.out crt1.o crti.o crtbegin.o -L -L/../../.. /tmp/cc-JJruTv.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o crtn.o
/usr/bin/ld: 1: Syntax error: word unexpected (expecting ")")
clang: error: linker command failed with exit code 2 (use -v to see invocation)
Sounds like a problem in your linker script. But the ld line above does not contain a specific linker script so the default one should be used (to see it simply type ld -v).
-L -L/../../..
that does look a bit weird. Don't see it on your original line though so not sure where it came from. Perhaps your installation is broken?
Do a gcc -v add.c and compare the lines invoking /usr/bin/ld. Perhaps add it to the question.

Resources