If I have the following program written in C (compiled with GCC on Debian 8.7), I am able to call atexit() as you would expect:
#include <stdlib.h>
void exit_handler(void) {
return;
}
int main () {
atexit(exit_handler);
return 0;
}
And when I compile and run it:
$ gcc test.c
$ ./a.out
Outputs nothing, just as you would expect. In fact, when I run ldd, I get:
$ ldd a.out
linux-vdso.so.1 (0x00007fffbe592000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe07d3a8000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe07d753000)
However, libc does not seem to have any symbols for atexit, amd only has__cxa_atexit and __cxa_threaded_atexit_impl:
$ nm --dynamic /lib/x86_64-linux-gnu/libc.so.6 | grep 'atexit'
0000000000037d90 T __cxa_atexit
0000000000037fa0 T __cxa_thread_atexit_impl
As you would then expect, if I try to link to libc dynamically, I cannot actually call atexit(), such as in the following Racket program which links to libc and tries to find atexit:
#lang racket
(require ffi/unsafe)
(get-ffi-obj 'atexit (ffi-lib "libc" '("6")) (_fun (_fun -> _void) -> _int))
Giving the output:
$ racket findatexit.rkt
ffi-obj: couldn't get "atexit" from "libc.so.6" (/lib/x86_64-linux-gnu/libc.so.6: undefined symbol: atexit)
What I want to know here is:
If libc does not have any symbol for atexit on Linux, why can I still call it from a C program?
Is there any way I can call atexit or a similar function dynamically on Linux?
(I should note that atexit does appear to be a symbol on OS X, so its just Linux that seems unusual here.)
Edit:
At the suggestion of #Jonathan, I also ran:
$ gcc -c test.c
$ nm test.o
U atexit
0000000000000000 T exit_handler
0000000000000007 T main
Which seems to indicate the atexit symbol is there somewhere, but it does not appear in any of the libraries ldd is showing.
I did some poking around on a Centos 7 virtual machine, and I think I found it — but it was anything but obvious!
Found it!
In /usr/lib64/libc_nonshared.a:
$ nm /usr/lib64/libc_nonshared.a | grep -i atexit
atexit.oS:
0000000000000000 T atexit
U __cxa_atexit
$
Why look in that library? Good question — and a long story. Are you sitting comfortably? Then I'll begin…
Steps taken to get there
Use the test.c code from the question.
Compile it with gcc -v test.c:
$ gcc -v test.c
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
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-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/cc1 -quiet -v test.c -quiet -dumpbase test.c -mtune=generic -march=x86-64 -auxbase test -version -o /tmp/ccPHTer7.s
GNU C (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-11) (x86_64-redhat-linux)
compiled by GNU C version 4.8.5 20150623 (Red Hat 4.8.5-11), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=96 --param ggc-min-heapsize=124992
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include
/usr/local/include
/usr/include
End of search list.
GNU C (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-11) (x86_64-redhat-linux)
compiled by GNU C version 4.8.5 20150623 (Red Hat 4.8.5-11), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=96 --param ggc-min-heapsize=124992
Compiler executable checksum: 356f86e67978d665416e07d560c8ba0d
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
as -v --64 -o /tmp/cc5WHEA4.o /tmp/ccPHTer7.s
GNU assembler version 2.25.1 (x86_64-redhat-linux) using BFD version version 2.25.1-22.base.el7
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2 --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../.. /tmp/cc5WHEA4.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o
$
The interesting part is the collect2 command line at the end. Written with one argument per line, that is:
/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2
--build-id
--no-add-needed
--eh-frame-hdr
--hash-style=gnu
-m
elf_x86_64
-dynamic-linker
/lib64/ld-linux-x86-64.so.2
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o
-L/usr/lib/gcc/x86_64-redhat-linux/4.8.5
-L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64
-L/lib/../lib64
-L/usr/lib/../lib64
-L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../..
/tmp/cc5WHEA4.o
-lgcc
--as-needed
-lgcc_s
--no-as-needed
-lc
-lgcc
--as-needed
-lgcc_s
--no-as-needed
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o
So, there are a bunch of cr*.o files, plus three libraries: -lc, -lgcc and -lgcc_s to look for, and a bunch of directories to look in:
-L/usr/lib/gcc/x86_64-redhat-linux/4.8.5, -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64, -L/lib/../lib64, -L/usr/lib/../lib64, -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../... The /tmp/cc5WHEA4.o is the object file created from test.c.
Applying some clean-up code to the path names, and then using ls to help find the libraries yields a list of files to examine further:
/lib64/ld-linux-x86-64.so.2
/usr/lib64/crt1.o
/usr/lib64/crti.o
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o
/usr/lib64/crtn.o
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/libgcc.a
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/libgcc_s.so
/usr/lib64/libgcc_s.so.1
/lib64/libgcc_s.so.1
/usr/lib64/libgcc_s.so.1
/usr/lib64/libc.so
/usr/lib64/libc.so.6
/lib64/libc.so
/lib64/libc.so.6
/usr/lib64/libc.so
/usr/lib64/libc.so.6
That list of files was saved in a file yy (unimaginative name), and then used in:
$ nm -o $(<yy) | tee nm.log | grep -i atexit
nm: _trampoline.o: no symbols
nm: __main.o: no symbols
nm: _ctors.o: no symbols
nm: /usr/lib/gcc/x86_64-redhat-linux/4.8.5/libgcc_s.so: no symbols
nm: /usr/lib64/libgcc_s.so.1: no symbols
nm: /lib64/libgcc_s.so.1: no symbols
nm: /usr/lib64/libgcc_s.so.1: no symbols
nm: /usr/lib64/libc.so: File format not recognized
/usr/lib64/libc.so.6:00000000003bcc00 b added_atexit_handler.9157
/usr/lib64/libc.so.6:0000000000038c90 T __cxa_atexit
/usr/lib64/libc.so.6:0000000000038c90 t __cxa_atexit_internal
/usr/lib64/libc.so.6:00000000003b6838 d __elf_set___libc_atexit_element__IO_cleanup__
/usr/lib64/libc.so.6:0000000000038c40 t __internal_atexit
/usr/lib64/libc.so.6:00000000003b6838 d __start___libc_atexit
/usr/lib64/libc.so.6:00000000003b6840 d __stop___libc_atexit
nm: /lib64/libc.so: File format not recognized
/lib64/libc.so.6:00000000003bcc00 b added_atexit_handler.9157
/lib64/libc.so.6:0000000000038c90 T __cxa_atexit
/lib64/libc.so.6:0000000000038c90 t __cxa_atexit_internal
/lib64/libc.so.6:00000000003b6838 d __elf_set___libc_atexit_element__IO_cleanup__
/lib64/libc.so.6:0000000000038c40 t __internal_atexit
nm: /usr/lib64/libc.so: File format not recognized
/lib64/libc.so.6:00000000003b6838 d __start___libc_atexit
/lib64/libc.so.6:00000000003b6840 d __stop___libc_atexit
/usr/lib64/libc.so.6:00000000003bcc00 b added_atexit_handler.9157
/usr/lib64/libc.so.6:0000000000038c90 T __cxa_atexit
/usr/lib64/libc.so.6:0000000000038c90 t __cxa_atexit_internal
/usr/lib64/libc.so.6:00000000003b6838 d __elf_set___libc_atexit_element__IO_cleanup__
/usr/lib64/libc.so.6:0000000000038c40 t __internal_atexit
/usr/lib64/libc.so.6:00000000003b6838 d __start___libc_atexit
/usr/lib64/libc.so.6:00000000003b6840 d __stop___libc_atexit
$
There's no evidence of a plain atexit function there. Where's it hiding, and what's with those 'File format not recognized' messages?
$ file /usr/lib64/libc.so
/usr/lib64/libc.so: ASCII text
$
ASCII text? What?
$ cat /usr/lib64/libc.so
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
$
OK; what's in /usr/lib64/libc_nonshared.a?
$ nm /usr/lib64/libc_nonshared.a | grep -i atexit
atexit.oS:
0000000000000000 T atexit
U __cxa_atexit
$
Bingo! Found it!
So, it seems that the collect2 linker used by GCC is able to load files not listed on the command line, and that one of those files is /usr/lib64/libc_nonshared.a, and that this library has atexit() in it. Consequently, you should be able to invoke atexit() because it is statically linked into the executable … unless there's some more black magic hidden away here that I've not sussed out.
Related
FIXED!
There are only 3 source code modules and no make file. One gcc command to compile and link as shown. I don't see any way everything could not have been compiled.
The matrix pointer I was trying to print was extracted from a larger structure array to an automatic variable. When I printed the full structure path in gdb, it worked.
When you explicitly turn off optimization and the verbose compiler output verifies it in the COLLECT_GCC_OPTIONS='-O0', it seems contradictory to "make debugging produce the expected results" to have variables optimized out and hidden.
Even with -0g, the aliased variable is still
Using gcc 9.3.1 on Opensuse leap 15.1
Set env var CFLAGS=""
used -O0 to turn off all optimization
I also tried using gcc 7.5.0
I am getting a segv. When I try to print the variables in gdb, they show
It looks like your post is mostly code; please add some more details.
moree details
even more details
That fixed it!???
user1#nova:~/bin> CFLAGS=""; gcc -v -O0 -g -m64 -Wuninitialized -fopenmp -I/usr/local/mysql/include -O0 /home/user1/bin/align_ppm.c -lm -lgd -lpng16 -lz -o /home/user1/bin/align_ppm_d
`/home/user1/bin/align_ppm_d' has changed; re-reading symbols.
Starting program: /home/user1/bin/align_ppm_d pf-2020.0805-291582.dt.ppm pf-2020.0805-291583.dt.ppm -d -d -s -d -f > ap23c.dt.log
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7fff58627700 (LWP 5330)]
[New Thread 0x7fff57e26700 (LWP 5331)]
[New Thread 0x7fff57625700 (LWP 5332)]
[New Thread 0x7fff56e24700 (LWP 5333)]
[New Thread 0x7fff56623700 (LWP 5334)]
[New Thread 0x7fff55e22700 (LWP 5335)]
[New Thread 0x7fff55621700 (LWP 5336)]
Thread 1 "align_ppm_d" received signal SIGSEGV, Segmentation fault.
0x00000000004a5631 in graph_hit_mis (mgc=0x718d80 <MGC>, smcss=0x719c10 <smcss>, gfinal=1, maia=0x719b70 <MMIA>,
tsa=0x71a440 <tsa>, debug=3) at /home/user1/bin/align_ppm.c:1240
1240 if((fmat[fy][fintoff]) & bmask) hitidx += 2; } // FIN
(gdb) p fmat
$151 = <optimized out>
(gdb) p fmat[fy][fintoff]
value has been optimized out
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc-9
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/9/lto-wrapper
OFFLOAD_TARGET_NAMES=hsa:nvptx-none
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,fortran,ada,go --enable-offload-targets=hsa,nvptx-none=/usr/nvptx-none, --without-cuda-driver --disable-werror --with-gxx-include-dir=/usr/include/c++/9 --enable-ssp --disable-libssp --disable-libvtv --disable-cet --disable-libcc1 --disable-plugin --with-bugurl=https://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --with-slibdir=/lib64 --with-system-zlib --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --with-gcc-major-version-only --enable-linker-build-id --enable-linux-futex --enable-gnu-indirect-function --program-suffix=-9 --without-system-libunwind --enable-multilib --with-arch-32=x86-64 --with-tune=generic --build=x86_64-suse-linux --host=x86_64-suse-linux
Thread model: posix
gcc version 9.3.1 20200406 [revision 6db837a5288ee3ca5ec504fbd5a765817e556ac2] (SUSE Linux)
COLLECT_GCC_OPTIONS='-v' '-O0' '-g' '-m64' '-Wuninitialized' '-fopenmp' '-I' '/usr/local/mysql/include' '-O0' '-o' '/home/user1/bin/align_ppm_d' '-mtune=generic' '-march=x86-64' '-pthread'
/usr/lib64/gcc/x86_64-suse-linux/9/cc1 -quiet -v -I /usr/local/mysql/include -D_REENTRANT /home/user1/bin/align_ppm.c -quiet -dumpbase align_ppm.c -m64 -mtune=generic -march=x86-64 -auxbase align_ppm -g -O0 -O0 -Wuninitialized -version -fopenmp -o /home/user1/tmp/cchRAKiS.s
GNU C17 (SUSE Linux) version 9.3.1 20200406 [revision 6db837a5288ee3ca5ec504fbd5a765817e556ac2] (x86_64-suse-linux)
compiled by GNU C version 9.3.1 20200406 [revision 6db837a5288ee3ca5ec504fbd5a765817e556ac2], GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.18-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
#include "..." search starts here:
#include <...> search starts here:
/usr/local/mysql/include
/usr/lib64/gcc/x86_64-suse-linux/9/include
/usr/local/include
/usr/lib64/gcc/x86_64-suse-linux/9/include-fixed
/usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/include
/usr/include
End of search list.
GNU C17 (SUSE Linux) version 9.3.1 20200406 [revision 6db837a5288ee3ca5ec504fbd5a765817e556ac2] (x86_64-suse-linux)
compiled by GNU C version 9.3.1 20200406 [revision 6db837a5288ee3ca5ec504fbd5a765817e556ac2], GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.18-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 00000000000000000000000000000000
COLLECT_GCC_OPTIONS='-v' '-O0' '-g' '-m64' '-Wuninitialized' '-fopenmp' '-I' '/usr/local/mysql/include' '-O0' '-o' '/home/user1/bin/align_ppm_d' '-mtune=generic' '-march=x86-64' '-pthread'
/usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/as -v -I /usr/local/mysql/include --64 -o /home/user1/tmp/ccCC3GjB.o /home/user1/tmp/cchRAKiS.s
GNU assembler version 2.32.0 (x86_64-suse-linux) using BFD version (GNU Binutils; openSUSE Leap 15.1) 2.32.0.20190909-lp151.3.6
COMPILER_PATH=/usr/lib64/gcc/x86_64-suse-linux/9/:/usr/lib64/gcc/x86_64-suse-linux/9/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/9/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/
LIBRARY_PATH=/usr/lib64/gcc/x86_64-suse-linux/9/:/usr/lib64/gcc/x86_64-suse-linux/9/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/lib/:/usr/lib64/gcc/x86_64-suse-linux/9/../../../:/lib/:/usr/lib/
Reading specs from /usr/lib64/gcc/x86_64-suse-linux/9/libgomp.spec
COLLECT_GCC_OPTIONS='-v' '-O0' '-g' '-m64' '-Wuninitialized' '-fopenmp' '-I' '/usr/local/mysql/include' '-O0' '-o' '/home/user1/bin/align_ppm_d' '-mtune=generic' '-march=x86-64' '-pthread'
/usr/lib64/gcc/x86_64-suse-linux/9/collect2 -plugin /usr/lib64/gcc/x86_64-suse-linux/9/liblto_plugin.so -plugin-opt=/usr/lib64/gcc/x86_64-suse-linux/9/lto-wrapper -plugin-opt=-fresolution=/home/user1/tmp/cc1z5Qzl.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o /home/user1/bin/align_ppm_d /usr/lib64/gcc/x86_64-suse-linux/9/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-suse-linux/9/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/9/crtbegin.o /usr/lib64/gcc/x86_64-suse-linux/9/crtoffloadbegin.o -L/usr/lib64/gcc/x86_64-suse-linux/9 -L/usr/lib64/gcc/x86_64-suse-linux/9/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/9/../../.. /home/user1/tmp/ccCC3GjB.o -lm -lgd -lpng16 -lz -lgomp -lgcc --push-state --as-needed -lgcc_s --pop-state -lpthread -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib64/gcc/x86_64-suse-linux/9/crtend.o /usr/lib64/gcc/x86_64-suse-linux/9/../../../../lib64/crtn.o /usr/lib64/gcc/x86_64-suse-linux/9/crtoffloadend.o
COLLECT_GCC_OPTIONS='-v' '-O0' '-g' '-m64' '-Wuninitialized' '-fopenmp' '-I' '/usr/local/mysql/include' '-O0' '-o' '/home/user1/bin/align_ppm_d' '-mtune=generic' '-march=x86-64' '-pthread'
gcc appears to optimize out aliased variables
When I tried to print the aliased version, gdb would only print
Printing the deeply nested original variable from an array of structures, it printed as expected.
In a similar question posted here compiling with -O0 fixed the problem. This did not work on my code.
I downloaded and built (seemingly correctly) the relevant BLAS and CBLAS libraries (from netlib.org/blas) in my Linux Fedora environment. The result of this was a blas_LINUX.a file, which I renamed libblas.a and copied to \usr\local\lib, and a cblas.h file which I copied to \usr\include. I subsequently tried referencing this in a CMakeList.txt file in a CLion project. The file is as follows:
project(test C)
cmake_minimum_required(VERSION 3.10)
set(CMAKE_C_STANDARD 99)
include_directories(include)
add_executable(${PROJECT_NAME} src/main.c)
find_library(blas libblas.a /usr/local/lib)
MESSAGE(STATUS "CBLAS location is: " ${blas})
target_link_libraries(${PROJECT_NAME} ${blas})
Going by the message that cmake produces when reloaded, the cblas library seems to get found fine. However when I try and run my application, I get the following linker error message:
undefined reference to `cblas_dgemm`
Following are the contents of my main.c file
#include <stdio.h>
#include <stdlib.h>
#include <cblas.h>
int main(int arg, char *args[]) {
.
.
.
printf("Processing cblas_dgemm matrix multiplication.\n");
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, N, N, N, alpha, A[0], N, B[0], N, beta, C[0], N);
.
.
.
return 0;
}
I'm not entirely sure where I'm going wrong here. I'm very new using cmake, and I'm going around in circles trying to figure out what the problems is, when searching online. Any pointers in the right direction would be greatly received, and appreciated.
Ammendment (CMakeOutput.txt is as follows)
The system is: Linux - 5.4.8-200.fc31.x86_64 - x86_64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: /usr/bin/cc
Build flags:
Id flags:
The output was:
0
Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "a.out"
The C compiler identification is GNU, found in "/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/3.15.3/CompilerIdC/a.out"
Determining if the C compiler works passed with the following output:
Change Dir: /home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/gmake cmTC_3ac25/fast && gmake[1]: Entering directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'
/usr/bin/gmake -f CMakeFiles/cmTC_3ac25.dir/build.make CMakeFiles/cmTC_3ac25.dir/build
gmake[2]: Entering directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_3ac25.dir/testCCompiler.c.o
/usr/bin/cc -o CMakeFiles/cmTC_3ac25.dir/testCCompiler.c.o -c /home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_3ac25
/home/xxx.xxx/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5662.56/bin/cmake/linux/bin/cmake -E cmake_link_script CMakeFiles/cmTC_3ac25.dir/link.txt --verbose=1
/usr/bin/cc -rdynamic CMakeFiles/cmTC_3ac25.dir/testCCompiler.c.o -o cmTC_3ac25
gmake[2]: Leaving directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'
gmake[1]: Leaving directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'
Detecting C compiler ABI info compiled with the following output:
Change Dir: /home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/gmake cmTC_8e81c/fast && gmake[1]: Entering directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'
/usr/bin/gmake -f CMakeFiles/cmTC_8e81c.dir/build.make CMakeFiles/cmTC_8e81c.dir/build
gmake[2]: Entering directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o
/usr/bin/cc -v -o CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o -c /home/xxx.xxx/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5662.56/bin/cmake/linux/share/cmake-3.15/Modules/CMakeCCompilerABI.c
Using built-in specs.
COLLECT_GCC=/usr/bin/cc
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.2.1 20190827 (Red Hat 9.2.1-1) (GCC)
COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64'
/usr/libexec/gcc/x86_64-redhat-linux/9/cc1 -quiet -v /home/xxx.xxx/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5662.56/bin/cmake/linux/share/cmake-3.15/Modules/CMakeCCompilerABI.c -quiet -dumpbase CMakeCCompilerABI.c -mtune=generic -march=x86-64 -auxbase-strip CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o -version -o /tmp/ccTuVrPj.s
GNU C17 (GCC) version 9.2.1 20190827 (Red Hat 9.2.1-1) (x86_64-redhat-linux)
compiled by GNU C version 9.2.1 20190827 (Red Hat 9.2.1-1), GMP version 6.1.2, MPFR version 3.1.6-p2, MPC version 1.1.0, isl version isl-0.16.1-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/9/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/9/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-redhat-linux/9/include
/usr/local/include
/usr/include
End of search list.
GNU C17 (GCC) version 9.2.1 20190827 (Red Hat 9.2.1-1) (x86_64-redhat-linux)
compiled by GNU C version 9.2.1 20190827 (Red Hat 9.2.1-1), GMP version 6.1.2, MPFR version 3.1.6-p2, MPC version 1.1.0, isl version isl-0.16.1-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 0e6902e158034d8f60c5405e0210406c
COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64'
as -v --64 -o CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o /tmp/ccTuVrPj.s
GNU assembler version 2.32 (x86_64-redhat-linux) using BFD version version 2.32-30.fc31
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64'
Linking C executable cmTC_8e81c
/home/xxx.xxx/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5662.56/bin/cmake/linux/bin/cmake -E cmake_link_script CMakeFiles/cmTC_8e81c.dir/link.txt --verbose=1
/usr/bin/cc -v -rdynamic CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o -o cmTC_8e81c
Using built-in specs.
COLLECT_GCC=/usr/bin/cc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.2.1 20190827 (Red Hat 9.2.1-1) (GCC)
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-rdynamic' '-o' 'cmTC_8e81c' '-mtune=generic' '-march=x86-64'
/usr/libexec/gcc/x86_64-redhat-linux/9/collect2 -plugin /usr/libexec/gcc/x86_64-redhat-linux/9/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper -plugin-opt=-fresolution=/tmp/ccTQ8sAE.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 --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -export-dynamic -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o cmTC_8e81c /usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/9/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/9 -L/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/9/../../.. CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.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-redhat-linux/9/crtend.o /usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crtn.o
COLLECT_GCC_OPTIONS='-v' '-rdynamic' '-o' 'cmTC_8e81c' '-mtune=generic' '-march=x86-64'
gmake[2]: Leaving directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'
gmake[1]: Leaving directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'
Parsed C implicit include dir info from above output: rv=done
found start of include info
found start of implicit include info
add: [/usr/lib/gcc/x86_64-redhat-linux/9/include]
add: [/usr/local/include]
add: [/usr/include]
end of search list found
collapse include dir [/usr/lib/gcc/x86_64-redhat-linux/9/include] ==> [/usr/lib/gcc/x86_64-redhat-linux/9/include]
collapse include dir [/usr/local/include] ==> [/usr/local/include]
collapse include dir [/usr/include] ==> [/usr/include]
implicit include dirs: [/usr/lib/gcc/x86_64-redhat-linux/9/include;/usr/local/include;/usr/include]
Parsed C implicit link information from above output:
link line regex: [^( *|.*[/\])(ld|CMAKE_LINK_STARTFILE-NOTFOUND|([^/\]+-)?ld|collect2)[^/\]*( |$)]
ignore line: [Change Dir: /home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp]
ignore line: []
ignore line: [Run Build Command(s):/usr/bin/gmake cmTC_8e81c/fast && gmake[1]: Entering directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp']
ignore line: [/usr/bin/gmake -f CMakeFiles/cmTC_8e81c.dir/build.make CMakeFiles/cmTC_8e81c.dir/build]
ignore line: [gmake[2]: Entering directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp']
ignore line: [Building C object CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o]
ignore line: [/usr/bin/cc -v -o CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o -c /home/xxx.xxx/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5662.56/bin/cmake/linux/share/cmake-3.15/Modules/CMakeCCompilerABI.c]
ignore line: [Using built-in specs.]
ignore line: [COLLECT_GCC=/usr/bin/cc]
ignore line: [OFFLOAD_TARGET_NAMES=nvptx-none]
ignore line: [OFFLOAD_TARGET_DEFAULT=1]
ignore line: [Target: x86_64-redhat-linux]
ignore line: [Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux]
ignore line: [Thread model: posix]
ignore line: [gcc version 9.2.1 20190827 (Red Hat 9.2.1-1) (GCC) ]
ignore line: [COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64']
ignore line: [ /usr/libexec/gcc/x86_64-redhat-linux/9/cc1 -quiet -v /home/xxx.xxx/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5662.56/bin/cmake/linux/share/cmake-3.15/Modules/CMakeCCompilerABI.c -quiet -dumpbase CMakeCCompilerABI.c -mtune=generic -march=x86-64 -auxbase-strip CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o -version -o /tmp/ccTuVrPj.s]
ignore line: [GNU C17 (GCC) version 9.2.1 20190827 (Red Hat 9.2.1-1) (x86_64-redhat-linux)]
ignore line: [ compiled by GNU C version 9.2.1 20190827 (Red Hat 9.2.1-1), GMP version 6.1.2, MPFR version 3.1.6-p2, MPC version 1.1.0, isl version isl-0.16.1-GMP]
ignore line: []
ignore line: [GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072]
ignore line: [ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/9/include-fixed"]
ignore line: [ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/9/../../../../x86_64-redhat-linux/include"]
ignore line: [#include "..." search starts here:]
ignore line: [#include <...> search starts here:]
ignore line: [ /usr/lib/gcc/x86_64-redhat-linux/9/include]
ignore line: [ /usr/local/include]
ignore line: [ /usr/include]
ignore line: [End of search list.]
ignore line: [GNU C17 (GCC) version 9.2.1 20190827 (Red Hat 9.2.1-1) (x86_64-redhat-linux)]
ignore line: [ compiled by GNU C version 9.2.1 20190827 (Red Hat 9.2.1-1), GMP version 6.1.2, MPFR version 3.1.6-p2, MPC version 1.1.0, isl version isl-0.16.1-GMP]
ignore line: []
ignore line: [GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072]
ignore line: [Compiler executable checksum: 0e6902e158034d8f60c5405e0210406c]
ignore line: [COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64']
ignore line: [ as -v --64 -o CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o /tmp/ccTuVrPj.s]
ignore line: [GNU assembler version 2.32 (x86_64-redhat-linux) using BFD version version 2.32-30.fc31]
ignore line: [COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/]
ignore line: [LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../:/lib/:/usr/lib/]
ignore line: [COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64']
ignore line: [Linking C executable cmTC_8e81c]
ignore line: [/home/xxx.xxx/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5662.56/bin/cmake/linux/bin/cmake -E cmake_link_script CMakeFiles/cmTC_8e81c.dir/link.txt --verbose=1]
ignore line: [/usr/bin/cc -v -rdynamic CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o -o cmTC_8e81c ]
ignore line: [Using built-in specs.]
ignore line: [COLLECT_GCC=/usr/bin/cc]
ignore line: [COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper]
ignore line: [OFFLOAD_TARGET_NAMES=nvptx-none]
ignore line: [OFFLOAD_TARGET_DEFAULT=1]
ignore line: [Target: x86_64-redhat-linux]
ignore line: [Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux]
ignore line: [Thread model: posix]
ignore line: [gcc version 9.2.1 20190827 (Red Hat 9.2.1-1) (GCC) ]
ignore line: [COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/]
ignore line: [LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../:/lib/:/usr/lib/]
ignore line: [COLLECT_GCC_OPTIONS='-v' '-rdynamic' '-o' 'cmTC_8e81c' '-mtune=generic' '-march=x86-64']
link line: [ /usr/libexec/gcc/x86_64-redhat-linux/9/collect2 -plugin /usr/libexec/gcc/x86_64-redhat-linux/9/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper -plugin-opt=-fresolution=/tmp/ccTQ8sAE.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 --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -export-dynamic -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o cmTC_8e81c /usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/9/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/9 -L/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/9/../../.. CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.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-redhat-linux/9/crtend.o /usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crtn.o]
arg [/usr/libexec/gcc/x86_64-redhat-linux/9/collect2] ==> ignore
arg [-plugin] ==> ignore
arg [/usr/libexec/gcc/x86_64-redhat-linux/9/liblto_plugin.so] ==> ignore
arg [-plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper] ==> ignore
arg [-plugin-opt=-fresolution=/tmp/ccTQ8sAE.res] ==> ignore
arg [-plugin-opt=-pass-through=-lgcc] ==> ignore
arg [-plugin-opt=-pass-through=-lgcc_s] ==> ignore
arg [-plugin-opt=-pass-through=-lc] ==> ignore
arg [-plugin-opt=-pass-through=-lgcc] ==> ignore
arg [-plugin-opt=-pass-through=-lgcc_s] ==> ignore
arg [--build-id] ==> ignore
arg [--no-add-needed] ==> ignore
arg [--eh-frame-hdr] ==> ignore
arg [--hash-style=gnu] ==> ignore
arg [-m] ==> ignore
arg [elf_x86_64] ==> ignore
arg [-export-dynamic] ==> ignore
arg [-dynamic-linker] ==> ignore
arg [/lib64/ld-linux-x86-64.so.2] ==> ignore
arg [-o] ==> ignore
arg [cmTC_8e81c] ==> ignore
arg [/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crt1.o] ==> ignore
arg [/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crti.o] ==> ignore
arg [/usr/lib/gcc/x86_64-redhat-linux/9/crtbegin.o] ==> ignore
arg [-L/usr/lib/gcc/x86_64-redhat-linux/9] ==> dir [/usr/lib/gcc/x86_64-redhat-linux/9]
arg [-L/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64] ==> dir [/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64]
arg [-L/lib/../lib64] ==> dir [/lib/../lib64]
arg [-L/usr/lib/../lib64] ==> dir [/usr/lib/../lib64]
arg [-L/usr/lib/gcc/x86_64-redhat-linux/9/../../..] ==> dir [/usr/lib/gcc/x86_64-redhat-linux/9/../../..]
arg [CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o] ==> ignore
arg [-lgcc] ==> lib [gcc]
arg [--push-state] ==> ignore
arg [--as-needed] ==> ignore
arg [-lgcc_s] ==> lib [gcc_s]
arg [--pop-state] ==> ignore
arg [-lc] ==> lib [c]
arg [-lgcc] ==> lib [gcc]
arg [--push-state] ==> ignore
arg [--as-needed] ==> ignore
arg [-lgcc_s] ==> lib [gcc_s]
arg [--pop-state] ==> ignore
arg [/usr/lib/gcc/x86_64-redhat-linux/9/crtend.o] ==> ignore
arg [/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crtn.o] ==> ignore
collapse library dir [/usr/lib/gcc/x86_64-redhat-linux/9] ==> [/usr/lib/gcc/x86_64-redhat-linux/9]
collapse library dir [/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64] ==> [/usr/lib64]
collapse library dir [/lib/../lib64] ==> [/lib64]
collapse library dir [/usr/lib/../lib64] ==> [/usr/lib64]
collapse library dir [/usr/lib/gcc/x86_64-redhat-linux/9/../../..] ==> [/usr/lib]
implicit libs: [gcc;gcc_s;c;gcc;gcc_s]
implicit dirs: [/usr/lib/gcc/x86_64-redhat-linux/9;/usr/lib64;/lib64;/usr/lib]
implicit fwks: []
Your CMakeLists.txt should have something that looks like this, following the FindBLAS suggestion:
include(FindBLAS)
if (BLAS_FOUND)
target_compile_options(${PROJECT_NAME} PRIVATE ${BLAS_LINKER_FLAGS})
target_link_libraries(${PROJECT_NAME} ${BLAS_LIBRARIES})
endif ()
Looks like the dynamic linker cannot find a shared library.
You can use ldd to inspect dynamic dependencies
Example looking at the dependencies of /bin/ls
ldd /bin/ls
linux-vdso.so.1 (0x00007ffcc3563000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f87e5459000)
libcap.so.2 => /lib64/libcap.so.2 (0x00007f87e5254000)
libc.so.6 => /lib64/libc.so.6 (0x00007f87e4e92000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f87e4c22000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f87e4a1e000)
/lib64/ld-linux-x86-64.so.2 (0x00005574bf12e000)
libattr.so.1 => /lib64/libattr.so.1 (0x00007f87e4817000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f87e45fa000)
Ensure the .so files exist at the path specified.
ldd manpage
I do not know how exactly you generated your libblas.a, but you could have a look at the FindBLAS CMake directive. (Take care about the note regarding C/C++)
https://cmake.org/cmake/help/v3.14/module/FindBLAS.html
There are a bunch of things that can go wrong here, but to simplify:
copy libblas.a into the same directory as your program
Reference it explicitly in the makefile.
Check to see the location of CBLAS in your output (not shown)
Verify the permissions of libblas.a, and look at the symbols using nm
Force CMake to link everything statically (e.g. here static link question
Your symptoms suggest that you are picking up some other blas library at compile but not at runtime.
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.
I've had some (too many) hours trying to make mariadb C connector to work with my own code. MySQL C connector worked fine, but I decided to migrate to mariadb.
Finally I decided to try a minimal code to check if the problem was with my code or the environment, and I got the same error. The code is from this question at SO: Using MariaDB in C.
#include <my_global.h>
#include <mysql.h>
int main(int argc, char **argv)
{
MYSQL *con = mysql_init(NULL);
if (con == NULL)
{
fprintf(stderr, "%s\n", mysql_error(con));
exit(1);
}
if (mysql_real_connect(con, "localhost", "root", "root_pswd",
NULL, 0, NULL, 0) == NULL)
{
fprintf(stderr, "%s\n", mysql_error(con));
mysql_close(con);
exit(1);
}
if (mysql_query(con, "CREATE DATABASE testdb"))
{
fprintf(stderr, "%s\n", mysql_error(con));
mysql_close(con);
exit(1);
}
mysql_close(con);
exit(0);
}
and tried to compile it with
gcc -v -o mysql-test mysql-test.c $(mariadb_config --libs)
expanded to
gcc -v -o mysql-test mysql-test.c $(mariadb_config --libs)
The output I got is
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3 --enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --program-suffix=-4.3 --enable-linux-futex --without-system-libunwind --with-cpu=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.3.4 [gcc-4_3-branch revision 152973] (SUSE Linux)
COLLECT_GCC_OPTIONS='-v' '-o' 'mysql-test' '-L/usr/local/lib/mariadb' '-mtune=generic'
/usr/lib64/gcc/x86_64-suse-linux/4.3/cc1 -quiet -v mysql-test.c -quiet -dumpbase mysql-test.c -mtune=generic -auxbase mysql-test -version -o /tmp/ccISncmQ.s
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib64/gcc/x86_64-suse-linux/4.3/include
/usr/lib64/gcc/x86_64-suse-linux/4.3/include-fixed
/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/include
/usr/include
End of search list.
GNU C (SUSE Linux) version 4.3.4 [gcc-4_3-branch revision 152973] (x86_64-suse-linux)
compiled by GNU C version 4.3.4 [gcc-4_3-branch revision 152973], GMP version 4.2.3, MPFR version 2.3.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 91a878d77972b76d647d592fefc786fc
COLLECT_GCC_OPTIONS='-v' '-o' 'mysql-test' '-L/usr/local/lib/mariadb' '-mtune=generic'
/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/as -V -Qy -o /tmp/ccD2nseu.o /tmp/ccISncmQ.s
GNU assembler version 2.20.0 (x86_64-suse-linux) using BFD version (GNU Binutils; SUSE Linux Enterprise 11) 2.20.0.20100122-0.7.9
COMPILER_PATH=/usr/lib64/gcc/x86_64-suse-linux/4.3/:/usr/lib64/gcc/x86_64-suse-linux/4.3/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.3/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/
LIBRARY_PATH=/usr/lib64/gcc/x86_64-suse-linux/4.3/:/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/lib/:/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'mysql-test' '-L/usr/local/lib/mariadb' '-mtune=generic'
/usr/lib64/gcc/x86_64-suse-linux/4.3/collect2 --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o mysql-test /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.3/crtbegin.o -L/usr/local/lib/mariadb -L/usr/lib64/gcc/x86_64-suse-linux/4.3 -L/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.3/../../.. /tmp/ccD2nseu.o -lmariadb -lssl -lnsl -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib64/gcc/x86_64-suse-linux/4.3/crtend.o /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/crtn.o
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_get_error#OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_get_peer_certificate#OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_CTX_load_verify_locations#OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_set_ex_data#OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `X509_STORE_CTX_get_error_depth#OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_get_ex_data#OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_write#OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_clear#OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `CRYPTO_THREADID_set_numeric#OPENSSL_1.0.0'
/usr/local/lib/mariadb/libmariadb.so: undefined reference to `SSL_COMP_get_compression_methods#OPENSSL_1.0.0'
...
LibOpenSSL 1.0.0 is installed and library in library path. I had to install libopenssl-devel, too.
At $LD_LIBRARY_PATH there is a libssl.so link to /lib64/libssl.so.1.0.0. If I execute
nm -g /usr/lib64/libssl.so
I get
nm: /usr/lib64/libssl.so: no symbols
libopenssl 0.9.8 is also installed
# rpm -qa | grep libopenssl
libopenssl0_9_8-0.9.8h-30.27.11
libopenssl-devel-1.0.0c-17.1
libopenssl0_9_8-32bit-0.9.8h-30.27.11
libopenssl1_0_0-1.0.0c-17.1
Any clue? Thanks!
Updated: Output of ldd
# ldd /usr/local/lib/mariadb/libmariadb.so
/usr/local/lib/mariadb/libmariadb.so: /lib64/libcrypto.so.1.0.0: no version information available (required by /usr/local/lib/mariadb/libmariadb.so)
/usr/local/lib/mariadb/libmariadb.so: /lib64/libssl.so.1.0.0: no version information available (required by /usr/local/lib/mariadb/libmariadb.so)
/usr/local/lib/mariadb/libmariadb.so: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /usr/local/lib/mariadb/libmariadb.so)
linux-vdso.so.1 => (0x00007fff2d90f000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f08bc078000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f08bbe73000)
libm.so.6 => /lib64/libm.so.6 (0x00007f08bbc1d000)
libssl.so.1.0.0 => /lib64/libssl.so.1.0.0 (0x00007f08bb9c1000)
libcrypto.so.1.0.0 => /lib64/libcrypto.so.1.0.0 (0x00007f08bb60f000)
libc.so.6 => /lib64/libc.so.6 (0x00007f08bb2b1000)
/lib64/ld-linux-x86-64.so.2 (0x00007f08bc521000)
libz.so.1 => /lib64/libz.so.1 (0x00007f08bb099000)
glicbc_2.14 not found, but it seems that libc.so.6 should be fine. At OpenSuse 11.4 repository glibc version is glibc-2.11.3-12.15.1.x86_64.rpm
Update 2: I succeeded in showing the symbos with
objdump -tT /usr/lib64/libssl.so
and the symbols are there
Update 3 and solution (workaround):
main problem is that libmariadb.so requires glibc 2.14, while at opensuse 11.4 glibc version is 2.11. Installing glibc 2.14 from opensuse 12.1 involved a severe upgrade of the system I could not do.
I also tried to use the connector from 2.0 series. It also failed with similar messages.
Next, I looked for 1.0 series. I read that previously the connector was named libmariadbclient and remembered that I installed a libmariadbclient package, so I changed linker flags to -lmariadbclient and... it worked!
But the linker didn't use the library from the libmariadbclient package, but the static library included with the connector (libmariadbclient.a). So linking statically the connector worked for me.
MariaDB Connector/C requires OpenSSL 1.0.1 or newer.
See Prerequisites For Building Connector/C From Source
Please also note, that OpenSSL versions < 1.0.2 are eoled and might be vulnerable.
Objective-C has a runtime that translates its syntax into functions that are organized and compiled. Does C have a runtime library? Also, if anyone can answer the question, what are the steps GCC takes during C compilation? e.g. main.c >> main.s >> main.bin
Yes, the C language features a standard library; that is, a number of standard macros, routines and types one can use in his programs, apart from any in the core language itself.
In popular implementations, there is a separate library file containing the code for the C standard library. For example, in GNU/Linux environments, the GNU C library (libc) is almost always present. Microsoft provides the msvcrt.dll runtime library for the Windows system, and so on.
Also, the C standard library might not be available in freestanding implementations. Sometimes it is possible to compile a program without linking against the C standard library from your system. As an example, the Windows API is well known for behaving as a freestanding C programming environment (although one might need to link against other system libraries specific to Windows).
Regarding GCC, the following illustrates briefly the compilation pipeline:
The input source is preprocessed with GNU cpp, resulting in a translation unit. (Actually, as Basile pointed out, nowadays no cpp process is created; the entire preprocessing work is done within cc1. Nevertheless, the resulting behavior is most likely the same as with cpp.)
The translation unit is then interpreted and compiled to assembly source with GCC cc1;
The assembly source is then assembled into object code with GNU as;
Finally, object files and libraries are linked together to produce a binary image with GNU ld.
Naturally, each of these steps may be altered or not executed at all depending on the driver options; the above is just a rough explanation of the overall process.
C has a standard library (libc on Linux, which provides standard functions like those in <stdio.h> such as fprintf and in <stdlib.h> such as malloc and also all the system calls), and even when you use gcc in free standing mode with gcc -ffreestanding (e.g. to compile a libc or some kernel) it links a tiny libgcc library which provides the functionality built-in the language (e.g. 64 bits addition on 32 bits platforms).
To learn what the gcc command is doing, pass it the -v flag. (Don't forget to take the habit to always compile with -Wall to get warnings and -g to get the debug information), e.g.
% gcc -v -g -Wall hello.c -o hello
Using built-in specs.
COLLECT_GCC=gcc
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='Debian 4.7.2-4' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --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-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --with-arch-32=i586 --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 (Debian 4.7.2-4)
COLLECT_GCC_OPTIONS='-v' '-g' '-Wall' '-o' 'hello' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.7/cc1 -quiet -v -imultiarch x86_64-linux-gnu hello.c -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello -g -Wall -version -o /tmp/ccsWt3UC.s
GNU C (Debian 4.7.2-4) version 4.7.2 (x86_64-linux-gnu)
compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version 3.1.0-p10, MPC version 0.9
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.7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/4.7/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C (Debian 4.7.2-4) version 4.7.2 (x86_64-linux-gnu)
compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version 3.1.0-p10, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: c5f63dedeacd449634699df94fe3d914
COLLECT_GCC_OPTIONS='-v' '-g' '-Wall' '-o' 'hello' '-mtune=generic' '-march=x86-64'
as -v --64 -o /tmp/ccO5i3pU.o /tmp/ccsWt3UC.s
GNU assembler version 2.22 (x86_64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.22
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='-v' '-g' '-Wall' '-o' 'hello' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.7/collect2 --sysroot=/ --build-id --no-add-needed --eh-frame-hdr -m elf_x86_64 --hash-style=both -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o hello /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/ccO5i3pU.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.7/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crtn.o
Notice that collect2 is the linker wrapped to do additional things, and that libc.so gets used by almost every Linux executable (because it is wrapping syscalls).
C has a standard library (e.g., strlen, malloc, etc.)
The steps are: compile your code that uses the standard library, then link your code to the standard library. libc can be contained in either a static library or a dynamic library, depending; usually both are available.