libquadmath.a is not installed but still found by gfortran - static-libraries

The man page of ld (which I think is used by gfortran in the background) says:
-lnamespec: ...If namespec is of the form :filename, ld will search the library path
for a file called filename...
Compiling the trivial Fortran program test.f:
END
with gfortran -l:libquadmath.a test.f does not throw an error on some of my machines (CENTOS 7 with GNU Fortran (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)).
However, for f in $(echo $LIBRARY_PATH | sed 's/:/ /g');do find $f -name libquadmath.a; done gives zero results, indicating that there is no file called libquadmath.a.
Additonally, the output of ld -l:libquadmath.a is ld: cannot find -l:libquadmath.a.
What is going on here?

Related

why `-R` after `-L` in Makefile

I saw -L/home/kgbook/tools/libiconv/lib -liconv -R/home/kgbook/tools/libiconv/lib when make VERBOSE=1.
What's the meaning of -R, I saw nothing when gcc --help or man gcc. No -R option or argument, neither gcc nor g++.
And why we need -R/home/kgbook/tools/libiconv/lib after -L/home/kgbook/tools/libiconv/lib -liconv?
I'm still confused after saw the question
Where should I insert "etags -R ." in makefile?.

configure freezes at "checking for ld used by GCC" - MSYS2

I have recently been experiencing problems with the configure step of two open source projects, GNU GetText and W3M.
The configure step fails at the same place for both projects.
checking for ld used by GCC...
System details:
Operating System: Windows 10 Pro 64-bit
MSYS2
gcc --version: gcc.exe (Rev4, Built by MSYS2 project) 5.2.0
gcc -dumpmachine: x86_64-w64-mingw32
bash --version: GNU bash, version 4.3.42(2)-release (x86_64-pc-msys)
Any ideas on what might be causing this?
The following is the code that configure uses to perform this test.
# Check if gcc -print-prog-name=ld gives a path.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by GCC" >&5
$as_echo_n "checking for ld used by GCC... " >&6; }
case $host in
*-*-mingw*)
# gcc leaves a trailing carriage return which upsets mingw
ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
*)
ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
esac
case $ac_prog in
# Accept absolute paths.
[\\/]* | [A-Za-z]:[\\/]*)
re_direlt='/[^/][^/]*/\.\./'
# Canonicalize the path of ld
ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'`
while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"`
done
test -z "$LD" && LD="$ac_prog"
;;
"")
# If it fails, then pretend we aren't using GCC.
ac_prog=ld
;;
*)
# If it is relative, then search for the first ld in PATH.
with_gnu_ld=unknown
;;
esac
I added debugging code to determine exactly where the problem is occurring. It is happening in the while loop in which grep is called.
I do not know why, but I found that the following packages interfered with configure.
mingw-w64-i686-grep
mingw-w64-i686-sed
mingw-w64-x86_64-grep
mingw-w64-x86_64-sed
These packages appear to be obsolete. When I removed them configure worked.

gcc: ignore unrecognized option

Is there a way to make gcc ignore an invalid option, instead of dying with "unrecongized option"? Reason is I want to use an option only available in later versions of gcc (-static-libstdc++), but it should also compile on older compilers. I could check for gcc version in the makefile but it is a bit ugly.
no, but you can set the flags based on the gcc version as follows:
version=`gcc --version | head -1 | cut -d ' ' -f3`
if [ `echo -e "$version\n4.6.1" | sort -V -C; echo $?` == 0 ]; then
flags = -static-libstdc++;
fi
gcc $flags ...
(Disclaimer: I'm not sure which version first uses static-libstdc++, 4.6.1 is just a guess).
John
You can run gcc and check if it accepts the flag:
STATIC_LIBCPP_FLAG := $(shell if gcc -static-libstdc++ --version 2>&1 | grep -q 'unrecognized option'; then true; else echo -static-libstdc++; fi)
CFLAGS += $(STATIC_LIBCPP_FLAG)

Does the order of -l and -L options in the GNU linker matter?

The -l option tells the linker to search the libraries in the standard dirs.
And with -L, we can specify our own library directories for searching.
Question: Does the sequence of order matters for the -L option too, like it does for the -l w.r.t the linker?
This link: http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html doesn't say much about the sequence of -L.
EDIT
Also,
Directories specified on the command
line are searched before the default
directories
is from the man page (as pointed by Dmitry), does this mean that even if I specify the order like:
gcc -lm hello.c -Lx
still the directory specified with -L will be given preference first?
Yes, the order of -L options matters - just like -l and -I options.
From man ld
-Lsearchdir
--library-path=searchdir
Add path searchdir to the list of paths that ld will search for archive libraries and ld control scripts. You may use this option any number of times. The directories are searched in the order in which they are specified on the command line. Directories specified on the command line are searched before the default directories. All -L options apply to all -l options, regardless of the order in which the options appear.
GCC documentations and more specifically Linking Options will be useful for you
Edit
Sorry, indeed I missed to check the link you've given. "man ld" can just be written in the console.
Edit2
I made a simple test putting -l before -L options and it shows no difference comparing to -L before -l
So answering your second question, this
gcc -lm hello.c -Lx
is equal to this
gcc -Lx -lm hello.c
libm is searched first in directory x/ in both tests.
Note though that putting -l<lib> before source files is a bad practice, that may lead to undefined references when linking. This is the correct way
gcc hello.c -Lx -lm

Make gcc/g++ use absolute path for warnings when compiling files in pwd

Is there a way to make gcc use the absolute path when printing errors found in files compiled in the current directory?
For instance the following does what I want when print errors:
g++ -I. -I../../.. /home/some/path/somefile.cpp
but I want to achieve the same with something like:
g++ -I. -I../../.. somefile.cpp
I want warnings and errors to be formatting something like:
/home/some/path/somefile.cpp:299:52: warning: some warning
There is no way to do this with gcc itself, but it's trivial with a wrapper script, installed as "gcc", "g++", etc in a directory before /usr/bin in your PATH:
#! /bin/sh
sourcefile="$1"; shift
case "$sourcefile" in
/*) ;;
*) sourcefile="$PWD/$sourcefile" ;;
esac
exec "/usr/bin/${0##*/}" "$sourcefile" "$#"
... provided that you always put the source file first in your compiler invocation (you'll have to tweak your Makefiles).

Resources