C [Freebsd 12.2] : GCC libc search path

Hi everybody

I've just installed the default lang/gcc package and
I'm surprised to have to add -L/usr/lib in order to ld: cannot find -lc link error message to disappear.

Code:
$ gcc -print-search-dirs
install: /usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/
programs: =/usr/local/libexec/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/:/usr/local/libexec/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/:
/usr/local/libexec/gcc10/gcc/x86_64-portbld-freebsd12.2/:/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/:/usr/local/lib/gcc10/g
cc/x86_64-portbld-freebsd12.2/:/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/../../../../../x86_64-portbld-freebsd12.2/bin/x86
_64-portbld-freebsd12.2/10.3.0/:/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/../../../../../x86_64-portbld-freebsd12.2/bin/
libraries: =/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/:/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/../../..
/../../x86_64-portbld-freebsd12.2/lib/x86_64-portbld-freebsd12.2/10.3.0/:/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/../../.
./../../x86_64-portbld-freebsd12.2/lib/:/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/../../../x86_64-portbld-freebsd12.2/10.3
.0/:/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/../../../:/lib/x86_64-portbld-freebsd12.2/10.3.0/:/lib/:/usr/lib/x86_64-port
bld-freebsd12.2/10.3.0/:/usr/lib/

Code:
$ gcc -dumpspecs
[...]
*link_command:
%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:    %(linker) %{!fno-use-linker-plugin:%{!fno-lto:     -plugin %(linker_plugin_file)     -plugin-
opt=%(lto_wrapper)     -plugin-opt=-fresolution=%u.res     %{flinker-output=*:-plugin-opt=-linker-output-known}     %{!nostdlib:%{!nodefaul
tlibs:%:pass-through-libs(%(link_gcc_c_sequence))}}     }}%{flto|flto=*:%<fcompare-debug*}     %{flto} %{fno-lto} %{flto=*} %l %{static|sha
red|r:;pie:-pie} %{fuse-ld=*:-fuse-ld=%*}  %{gz|gz=zlib:--compress-debug-sections=zlib} %{gz=none:--compress-debug-sections=none} %{gz=zlib
-gnu:--compress-debug-sections=zlib-gnu} %X %{o*} %{e*} %{N} %{n} %{r}    %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}}
    %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) %{fvtable-verify=none:} %{fvtable-verify=std:   %e-fvtable-verify=std is n
ot supported in this configuration} %{fvtable-verify=preinit:   %e-fvtable-verify=preinit is not supported in this configuration} %{!nostdl
ib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):}     %{%:sanitize(thread):}     %{%:sanitize(leak):}}}} %o      %{fopenacc|fopenmp|%:gt(%{f
tree-parallelize-loops=*:%*} 1):        %:include(libgomp.spec)%(link_gomp)}    %{fgnu-tm:%:include(libitm.spec)%(link_itm)}    %(mflib)  %
{fsplit-stack: --wrap=pthread_create}    %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize
(address):%{static-libasan:-Bstatic} -lasan %{static-libasan:-Bdynamic} %{static-libasan|static:%:include(libsanitizer.spec)%(link_libasan)
}    %{static:%ecannot specify -static with -fsanitize=address}}    %{%:sanitize(thread):%{static-libtsan:-Bstatic} -ltsan %{static-libtsan
:-Bdynamic} %{static-libtsan|static:%:include(libsanitizer.spec)%(link_libtsan)}    %{static:%ecannot specify -static with -fsanitize=threa
d}}    %{%:sanitize(undefined):%{static-libubsan:-Bstatic} -lubsan %{static-libubsan:-Bdynamic} %{static-libubsan|static:%:include(libsanit
izer.spec)%(link_libubsan)}}    %{%:sanitize(leak):%{static-liblsan:-Bstatic} -llsan %{static-liblsan:-Bdynamic} %{static-liblsan|static:%:
include(libsanitizer.spec)%(link_liblsan)}}}}}     %{!nostdlib:%{!r:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}}    %{!nostdlib:%
{!r:%{!nostartfiles:%E}}} %{T*}  
%(post_link) }}}}}}

Code:
$ ld --version
LLD 10.0.1 (FreeBSD llvmorg-10.0.1-0-gef32c611aa2-1200012) (compatible with GNU linkers)

Is there something wrong in my installation ?

Thank you a lot.
Cheers
Didier.
 
In so many levels:

1. Don't mix CLANG and GCC toolchains, esp. in the Link phase. Compilation phase and libraries are different story -- not a good one!
2. Is it a C program or a C++ one (cc, g++)?
3. cc -v output?
4. /usr/bin/cc is a hard link to what?
# find /usr/bin -inum `ls -i /usr/bin/cc | cut -d ' ' -f 1`
5. What is the original executed command and the error message? (pre -L/usr/lib)
6. Not so related, but do you have any customized src.conf and/or make.conf?
0. And finally, what happened to the 2014 Manifesto! Use the [CODE]...[/CODE] tags for the output.
 
In so many levels:

1. Don't mix CLANG and GCC toolchains, esp. in the Link phase. Compilation phase and libraries are different story -- not a good one!
Don't want to. We do not expect that a gcc tool calling an clang tool. This should be a gcc weakness, should it ?
2. Is it a C program or a C++ one (cc, g++)?
Just testing with the simplest C program ever :

C:
int main(int argc, char* argv[])
{
   return 0;
}
3. cc -v output?
Not changed default compiler yet.
Code:
FreeBSD clang version 10.0.1 (git@github.com:llvm/llvm-project.git llvmorg-10.0.1-0-gef32c611aa2)
Target: x86_64-unknown-freebsd12.2
Thread model: posix
InstalledDir: /usr/bin
4. /usr/bin/cc is a hard link to what?
$ find /usr/bin -inum 16542794
Code:
/usr/bin/clang
/usr/bin/c++
/usr/bin/cc
/usr/bin/clang-cpp
/usr/bin/cpp
/usr/bin/clang++
5. What is the original executed command and the error message? (pre -L/usr/lib)
$ gcc foo.c
6. Not so related, but do you have any customized src.conf and/or make.conf?
Not at all.
And I do all of these in a chrooted installation.
0. And finally, what happened to the 2014 Manifesto! Use the [CODE]...[/CODE] tags for the output.
I've just reviewed again 2014 Manifesto and haven't seen any recommendation about command's output (neither for stdout, neither for stderr).
I've badly read it, maybe ... May you tell me where to see.

Anyway, thank you to pay attention to my trouble.
 
I built my lang/gcc (and its dependencies) using Poudriere. Not sure what's going on with your gcc, but it seems to work fine on my x86_64 machine with any linker available:
Code:
$ doas pkg install gcc
    [...]
$ cat hello.c
    #include <stdio.h>
    int main(void)
    {
        printf("Hello, world!\n");
        return 0;
    }
$ cat hello.sh
    rm -f ./hello.bfd ; gcc -fuse-ld=bfd  -o ./hello.bfd  ./hello.c && ./hello.bfd
    rm -f ./hello.gold; gcc -fuse-ld=gold -o ./hello.gold ./hello.c && ./hello.gold
    rm -f ./hello.lld ; gcc -fuse-ld=lld  -o ./hello.lld  ./hello.c && ./hello.lld
    rm -f ./hello.none; gcc               -o ./hello.none ./hello.c && ./hello.none
    rm -f              \
          ./hello.bfd  \
          ./hello.gold \
          ./hello.lld  \
          ./hello.none
$ sh hello.sh
    Hello, world!
    Hello, world!
    Hello, world!
    Hello, world!

What is the output of gcc -v foo.c >/dev/null on your system?
 
Code:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/lto-wrapper
Target: x86_64-portbld-freebsd12.2
Configured with: /wrkdirs/usr/ports/lang/gcc10/work/gcc-10.3.0/configure --enable-multilib --with-build-config=bootstrap-debug --disable-nls --enable-g
nu-indirect-function --enable-plugin --libdir=/usr/local/lib/gcc10 --libexecdir=/usr/local/libexec/gcc10 --program-suffix=10 --with-as=/usr/local/bin/a
s --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc10/include/c++/ --with-ld=/usr/local/bin/ld --with-pkgversion='FreeBSD Ports Collectio
n' --with-system-zlib --without-zstd --enable-languages=c,c++,objc,fortran --prefix=/usr/local --localstatedir=/var --mandir=/usr/local/man --infodir=/
usr/local/share/info/gcc10 --build=x86_64-portbld-freebsd12.2
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.3.0 (FreeBSD Ports Collection)
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
/usr/local/libexec/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/cc1 -quiet -v foo.c -quiet -dumpbase foo.c -mtune=generic -march=x86-64 -auxbase foo -v
ersion -o /tmp//ccf32UbO.s
GNU C17 (FreeBSD Ports Collection) version 10.3.0 (x86_64-portbld-freebsd12.2)
        compiled by GNU C version 10.3.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.0, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/include-fixed"
ignoring nonexistent directory "/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/../../../../../x86_64-portbld-freebsd12.2/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/include
/usr/local/include
/usr/include
End of search list.
GNU C17 (FreeBSD Ports Collection) version 10.3.0 (x86_64-portbld-freebsd12.2)
        compiled by GNU C version 10.3.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.0, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: f427813f219dcfe5c543a89fbd23543d
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
/usr/local/bin/as -v -o /tmp//ccrTNfZ1.o /tmp//ccf32UbO.s
GNU assembler version 2.35.2 (x86_64-unknown-freebsd12.2) using BFD version (GNU Binutils) 2.35.2
COMPILER_PATH=/usr/local/libexec/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/:/usr/local/libexec/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/:/usr/loca
l/libexec/gcc10/gcc/x86_64-portbld-freebsd12.2/:/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/:/usr/local/lib/gcc10/gcc/x86_64-portbld-fre
ebsd12.2/:/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/../../../../../x86_64-portbld-freebsd12.2/bin/
LIBRARY_PATH=/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/:/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/../../../../../x86_
64-portbld-freebsd12.2/lib/:/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
/usr/local/libexec/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/collect2 -plugin /usr/local/libexec/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/liblto_
plugin.so -plugin-opt=/usr/local/libexec/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/lto-wrapper -plugin-opt=-fresolution=/tmp//ccIkalgg.res -plugin-op
t=-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 -m elf_x86_64_fbsd -V -dynamic-linker /libexec/ld-elf.so.1 /usr/lib/crt1.o /usr/lib/crti.o /usr/local/lib/gcc10/gcc/x86_64-portbld-free
bsd12.2/10.3.0/crtbegin.o -L/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0 -L/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/../
../../../../x86_64-portbld-freebsd12.2/lib -L/usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/../../.. /tmp//ccrTNfZ1.o -lgcc --push-state --
as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/local/lib/gcc10/gcc/x86_64-portbld-freebsd12.2/10.3.0/crtend.
o /usr/lib/crtn.o
/usr/local/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status

Surprising ! LIBRARY_PATH contains /usr/lib that contains itself libc.so and libc.a

$ ls /usr/lib/libc*
Code:
/usr/lib/libc_nonshared.a       /usr/lib/libcam.a               /usr/lib/libcompiler_rt_p.a     /usr/lib/libcursesw.a
/usr/lib/libc_p.a               /usr/lib/libcam.so              /usr/lib/libcompiler_rt.a       /usr/lib/libcursesw.so
/usr/lib/libc_pic.a             /usr/lib/libcap_dns.so          /usr/lib/libcrypt_p.a           /usr/lib/libcuse_p.a
/usr/lib/libc.a                 /usr/lib/libcap_grp.so          /usr/lib/libcrypt.a             /usr/lib/libcuse.a
/usr/lib/libc.so                /usr/lib/libcap_pwd.so          /usr/lib/libcrypt.so            /usr/lib/libcuse.so
/usr/lib/libc++_p.a             /usr/lib/libcap_random.so       /usr/lib/libcrypto_p.a          /usr/lib/libcuse.so.1
/usr/lib/libc++.a               /usr/lib/libcap_sysctl.so       /usr/lib/libcrypto.a            /usr/lib/libcxgb4.a
/usr/lib/libc++.so              /usr/lib/libcap_syslog.so       /usr/lib/libcrypto.so           /usr/lib/libcxgb4.so
/usr/lib/libc++.so.1            /usr/lib/libcasper.so           /usr/lib/libctf_p.a             /usr/lib/libcxgb4.so.1
/usr/lib/libc++experimental.a   /usr/lib/libcom_err_p.a         /usr/lib/libctf.a               /usr/lib/libcxxrt_p.a
/usr/lib/libcalendar_p.a        /usr/lib/libcom_err.a           /usr/lib/libctf.so              /usr/lib/libcxxrt.a
/usr/lib/libcalendar.a          /usr/lib/libcom_err.so          /usr/lib/libcurses_p.a          /usr/lib/libcxxrt.so
/usr/lib/libcalendar.so         /usr/lib/libcom_err.so.5        /usr/lib/libcurses.a
/usr/lib/libcalendar.so.5       /usr/lib/libcompat_p.a          /usr/lib/libcurses.so
/usr/lib/libcam_p.a             /usr/lib/libcompat.a            /usr/lib/libcursesw_p.a
 
Last edited by a moderator:
Back
Top