I use window10 with WSL, linux version is ubuntu20.0.4
When I use riscv64-unknown-elf-gcc -lc --verbose to check some information,
The log is as follows :
Using built-in specs.
COLLECT_GCC=riscv64-unknown-elf-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/riscv64-unknown-elf/9.3.0/lto-wrapper
Target: riscv64-unknown-elf
Configured with: ../configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --disable-silent-rules --libdir='/usr/lib/x86_64-linux-gnu' --libexecdir='/usr/lib/x86_64-linux-gnu' --disable-maintainer-mode --disable-dependency-tracking --target=riscv64-unknown-elf --prefix=/usr --infodir=/usr/share/doc/gcc-riscv64-unknown-elf/info --mandir=/usr/share/man --htmldir=/usr/share/doc/gcc-riscv64-unknown-elf/html --pdfdir=/usr/share/doc/gcc-riscv64-unknown-elf/pdf --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --with-pkgversion= --disable-shared --disable-threads --enable-languages=c,c++ --enable-tls --with-newlib --with-native-system-header-dir=/include --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libgomp --disable-nls --with-system-zlib --enable-checking=yes --enable-multilib --with-abi=lp64d --disable-libstdcxx-pch --disable-libstdcxx --disable-fixinc --with-arch=rv64imafdc --with-gnu-as --with-gnu-ld --with-as=/usr/lib/riscv64-unknown-elf/bin/as --with-ld=/usr/lib/riscv64-unknown-elf/bin/ld AR_FOR_TARGET=/usr/lib/riscv64-unknown-elf/bin/ar AS_FOR_TARGET=/usr/lib/riscv64-unknown-elf/bin/as NM_FOR_TARGET=/usr/lib/riscv64-unknown-elf/bin/nm LD_FOR_TARGET=/usr/lib/riscv64-unknown-elf/bin/ld OBJDUMP_FOR_TARGET=/usr/lib/riscv64-unknown-elf/bin/objdump RANLIB_FOR_TARGET=/usr/lib/riscv64-unknown-elf/bin/ranlib READELF_FOR_TARGET=/usr/lib/riscv64-unknown-elf/bin/readelf STRIP_FOR_TARGET=/usr/lib/riscv64-unknown-elf/bin/strip CFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-riscv64-unknown-elf-3seJsn/gcc-riscv64-unknown-elf-9.3.0=. -fstack-protector-strong' CPPFLAGS='-Wdate-time -D_FORTIFY_SOURCE=2' CXXFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-riscv64-unknown-elf-3seJsn/gcc-riscv64-unknown-elf-9.3.0=. -fstack-protector-strong' FCFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-riscv64-unknown-elf-3seJsn/gcc-riscv64-unknown-elf-9.3.0=. -fstack-protector-strong' FFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-riscv64-unknown-elf-3seJsn/gcc-riscv64-unknown-elf-9.3.0=. -fstack-protector-strong' GCJFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-riscv64-unknown-elf-3seJsn/gcc-riscv64-unknown-elf-9.3.0=. -fstack-protector-strong' LDFLAGS='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now' OBJCFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-riscv64-unknown-elf-3seJsn/gcc-riscv64-unknown-elf-9.3.0=. -fstack-protector-strong' OBJCXXFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-riscv64-unknown-elf-3seJsn/gcc-riscv64-unknown-elf-9.3.0=. -fstack-protector-strong' 'CFLAGS_FOR_TARGET=-Os -mcmodel=medany' 'CXXFLAGS_FOR_TARGET=-Os -mcmodel=medany'
Thread model: single
gcc version 9.3.0 ()
COMPILER_PATH=/usr/lib/gcc/riscv64-unknown-elf/9.3.0/:/usr/lib/gcc/riscv64-unknown-elf/9.3.0/:/usr/lib/gcc/riscv64-unknown-elf/:/usr/lib/gcc/riscv64-unknown-elf/9.3.0/:/usr/lib/gcc/riscv64-unknown-elf/
LIBRARY_PATH=/usr/lib/gcc/riscv64-unknown-elf/9.3.0/rv64imafdc/lp64d/:/usr/lib/gcc/riscv64-unknown-elf/9.3.0/:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-march=rv64imafdc' '-mabi=lp64d'
/usr/lib/gcc/riscv64-unknown-elf/9.3.0/collect2 -plugin /usr/lib/gcc/riscv64-unknown-elf/9.3.0/liblto_plugin.so -plugin-opt=/usr/lib/gcc/riscv64-unknown-elf/9.3.0/lto-wrapper -plugin-opt=-fresolution=/tmp/cc2p9LDX.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgloss -plugin-opt=-pass-through=-lgcc -melf64lriscv crt0.o /usr/lib/gcc/riscv64-unknown-elf/9.3.0/rv64imafdc/lp64d/crtbegin.o -L/usr/lib/gcc/riscv64-unknown-elf/9.3.0/rv64imafdc/lp64d -L/usr/lib/gcc/riscv64-unknown-elf/9.3.0 -lc -lgcc --start-group -lc -lgloss --end-group -lgcc /usr/lib/gcc/riscv64-unknown-elf/9.3.0/rv64imafdc/lp64d/crtend.o
/usr/lib/riscv64-unknown-elf/bin/ld: cannot find crt0.o: No such file or directory
/usr/lib/riscv64-unknown-elf/bin/ld: cannot find -lc
/usr/lib/riscv64-unknown-elf/bin/ld: cannot find -lc
/usr/lib/riscv64-unknown-elf/bin/ld: cannot find -lgloss
collect2: error: ld returned 1 exit status
I think I lose the libc and libgloss, but I don't know how to fix it.
Related
Let's say I run the following command to compile/run a basic C program which returns the result 48:
$ gcc -v -o file.o file.c && ./file.o; echo $?
# 48
The -v flag returns a lot of data, for example:
$ gcc -v -o file.o file.c && ./file.o; echo $?
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.4-2ubuntu1~14.04.1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --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-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --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.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1)
COLLECT_GCC_OPTIONS='-v' '-o' 'file.o' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.8/cc1 -quiet -v -imultiarch x86_64-linux-gnu file.c -quiet -dumpbase file.c -mtune=generic -march=x86-64 -auxbase file -version -fstack-protector -Wformat -Wformat-security -o /tmp/ccZ9MZvc.s
GNU C (Ubuntu 4.8.4-2ubuntu1~14.04.1) version 4.8.4 (x86_64-linux-gnu)
compiled by GNU C version 4.8.4, GMP version 5.1.3, MPFR version 3.1.2-p3, MPC version 1.0.1
warning: MPFR header version 3.1.2-p3 differs from library version 3.1.3.
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/4.8/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/4.8/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C (Ubuntu 4.8.4-2ubuntu1~14.04.1) version 4.8.4 (x86_64-linux-gnu)
compiled by GNU C version 4.8.4, GMP version 5.1.3, MPFR version 3.1.2-p3, MPC version 1.0.1
warning: MPFR header version 3.1.2-p3 differs from library version 3.1.3.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 47b61fdffcea151b8f9b26c4df78cd3c
COLLECT_GCC_OPTIONS='-v' '-o' 'file.o' '-mtune=generic' '-march=x86-64'
as -v --64 -o /tmp/cc5PIIv9.o /tmp/ccZ9MZvc.s
GNU assembler version 2.24 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.24
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../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.8/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'file.o' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.8/collect2 --sysroot=/ --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro -o file.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.8/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../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.8/../../.. /tmp/cc5PIIv9.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
48
From what I gather (I think?) the three commands it is running are:
/usr/lib/gcc/x86_64-linux-gnu/4.8/cc1 -quiet -v -imultiarch x86_64-linux-gnu file.c -quiet -dumpbase file.c -mtune=generic -march=x86-64 -auxbase file -version -fstack-protector -Wformat -Wformat-security -o /tmp/ccZ9MZvc.s
as -v --64 -o /tmp/cc5PIIv9.o /tmp/ccZ9MZvc.s
/usr/lib/gcc/x86_64-linux-gnu/4.8/collect2 --sysroot=/ --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro -o file.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.8/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../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.8/../../.. /tmp/cc5PIIv9.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
Is that correct, or is it running other commands as well that I may have missed. I know this is very broad, but could someone explain basically what those three commands are doing / perhaps re-writing them to exclude any non-essential options?
After playing around with it a bit it seems like it can be boiled down to (roughly):
$ cc1 file.c -o file.s
$ as -o file.o file.s
But the collect2 / ld command has been a bit tricky.
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.
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
I want to build Asterisk PBX under Windows, it seems to be possible by using cygwin.
The configure script complains about not finding the uuid_generate_random method in the uuid library.
So I tried to create a little test program :
#include <uuid/uuid.h>
int main ()
{
uuid_t out;
uuid_generate_random(out);
return 0;
}
This program is compiled using this command : gcc uuid.c -luuid
The -luuid seems to works, as if I change this value (like -luuidX) gcc complains about the fact it can't find the uuidX library.
But the LD pass doesn't works :
$ gcc uuid.c -luuid
/tmp/ccu0oh9q.o:uuid.c:(.text+0x16): undefined reference to `uuid_generate_random'
collect2: error: ld returned 1 exit status
I manage to work around, but this is not really clean, and I don't know how to make the configure script take this tweak :
gcc -o uuid.exe uuid.o /cygdrive/c/cygwin/lib/libuuid.dll.a
Any idea where does the problem come from ?
Thanks.
Added : verbose gcc output
gcc -v uuid.c -luuid
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-cygwin/5.3.0/lto-wrapper.exe
Target: i686-pc-cygwin
Configured with: /cygdrive/i/szsz/tmpp/gcc/gcc-5.3.0-4.i686/src/gcc-5.3.0/configure --srcdir=/cygdrive/i/szsz/tmpp/gcc/gcc-5.3.0-4.i686/src/gcc-5.3.0 --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=i686-pc-cygwin --host=i686-pc-cygwin --target=i686-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit --with-dwarf2 --with-arch=i686 --with-tune=generic --disable-sjlj-exceptions --enable-languages=ada,c,c++,fortran,java,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libatomic --enable-libcilkrts --enable-libgomp --enable-libitm --enable-libquadmath --enable-libquadmath-support --enable-libssp --enable-libada --enable-libjava --enable-libgcj-sublibs --disable-java-awt --disable-symvers --with-ecj-jar=/usr/share/java/ecj.jar --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible
Thread model: posix
gcc version 5.3.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=i686'
/usr/lib/gcc/i686-pc-cygwin/5.3.0/cc1.exe -quiet -v -Dunix -idirafter /usr/lib/../include/w32api -idirafter /usr/lib/gcc/i686-pc-cygwin/5.3.0/../../../../i686-pc-cygwin/lib/../../include/w32api uuid.c -quiet -dumpbase uuid.c -mtune=generic -march=i686 -auxbase uuid -version -o /tmp/ccVIcgnD.s
GNU C11 (GCC) version 5.3.0 (i686-pc-cygwin)
compiled by GNU C version 5.3.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/5.3.0/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/5.3.0/../../../../i686-pc-cygwin/include"
ignoring duplicate directory "/usr/lib/gcc/i686-pc-cygwin/5.3.0/../../../../i686-pc-cygwin/lib/../../include/w32api"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/i686-pc-cygwin/5.3.0/include
/usr/include
/usr/lib/../include/w32api
End of search list.
GNU C11 (GCC) version 5.3.0 (i686-pc-cygwin)
compiled by GNU C version 5.3.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: f4218c97435c4e66cb956a0e671020d7
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=i686'
/usr/lib/gcc/i686-pc-cygwin/5.3.0/../../../../i686-pc-cygwin/bin/as.exe -v -o /tmp/cc0dlffC.o /tmp/ccVIcgnD.s
GNU assembler version 2.25.2 (i686-pc-cygwin) using BFD version (GNU Binutils) 2.25.2
COMPILER_PATH=/usr/lib/gcc/i686-pc-cygwin/5.3.0/:/usr/lib/gcc/i686-pc-cygwin/5.3.0/:/usr/lib/gcc/i686-pc-cygwin/:/usr/lib/gcc/i686-pc-cygwin/5.3.0/:/usr/lib/gcc/i686-pc-cygwin/:/usr/lib/gcc/i686-pc-cygwin/5.3.0/../../../../i686-pc-cygwin/bin/
LIBRARY_PATH=/usr/lib/gcc/i686-pc-cygwin/5.3.0/:/usr/lib/gcc/i686-pc-cygwin/5.3.0/../../../../i686-pc-cygwin/lib/:/usr/lib/:/lib/:/usr/lib/w32api/
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=i686'
/usr/lib/gcc/i686-pc-cygwin/5.3.0/collect2.exe -plugin /usr/lib/gcc/i686-pc-cygwin/5.3.0/cyglto_plugin.dll -plugin-opt=/usr/lib/gcc/i686-pc-cygwin/5.3.0/lto-wrapper.exe -plugin-opt=-fresolution=/tmp/ccFo5pxm.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lcygwin -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 --wrap _Znwj --wrap _Znaj --wrap _ZdlPv --wrap _ZdaPv --wrap _ZnwjRKSt9nothrow_t --wrap _ZnajRKSt9nothrow_t --wrap _ZdlPvRKSt9nothrow_t --wrap _ZdaPvRKSt9nothrow_t -Bdynamic --dll-search-prefix=cyg --large-address-aware --tsaware /usr/lib/crt0.o /usr/lib/gcc/i686-pc-cygwin/5.3.0/crtbegin.o -L/usr/lib/gcc/i686-pc-cygwin/5.3.0 -L/usr/lib/gcc/i686-pc-cygwin/5.3.0/../../../../i686-pc-cygwin/lib -L/usr/lib/w32api /tmp/cc0dlffC.o -luuid -lgcc_s -lgcc -lcygwin -ladvapi32 -lshell32 -luser32 -lkernel32 -lgcc_s -lgcc /usr/lib/default-manifest.o /usr/lib/gcc/i686-pc-cygwin/5.3.0/crtend.o
/tmp/cc0dlffC.o:uuid.c:(.text+0x16): undefined reference to `uuid_generate_random'
collect2: error: ld returned 1 exit status
It is a gcc package error. As workaround use
gcc uuid.c -luuid -L/usr/lib
Reported to cygwin mailing list
https://cygwin.com/ml/cygwin/2016-04/msg00594.html
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