I have been getting the error below when compiling and running my application for 64-bit release (release just has optimisation level -O2
on that debug does not).
The 32-bit debug version runs ok. The 64-bit debug version crashes (this is what I am trying to solve), but the 64-bit release version gives me this error. I am guessing that they are related - but not 100% sure about that.
Here is the error:
./tester_x64Linux: relocation error: /home/user/development/lib/libcontroller_library_x64Linux.so.0: symbol nanosleep version GLIBC_2.2.5 not defined in file libpthread.so.0 with link time reference
I am running on ubuntu 18:04 with c++17 standard and I have tested this with gccv7 and gccv8 both with the same results.
Note: that I compile the library with the same make tools (and flags etc) as I do my binary
so /home/user/development/lib/libcontroller_library_x64Linux.so.0
is compiled first and then tester_x64Linux
is compiled.
After tsrying to read about what the GLIBC error is trying to tell me, I find I am hitting lots of false positives (in google searches) because there seems to be some oldes issues like GLIBC verno.h
file not included in older GBLIC versions (2.0 IIRC).
I do have some threads running and I used functions like std::this_thread::sleepfor(...)
which I believe use nanosleep
under the hood.
So now I am not quite sure how to progress. Usually this would (IMO) imply some library that I have linked needs to be recompiled with newer GLIBC - but in this case its a library that I am compiling and have re-compiled every time I compile my binary (if I do a clean) - so it should be compiled to the same level as my executable.
Maybe my libpthread.so.0
is too old? - but then I would be very confused as I have used this on many other projects (with the same libraries) with no problems (thus far).
update: just tested this against 2 other applications that are built in the exact same way with the same libraries - just different app code, but that have threads - and they are both ok (just confused now).
Any pointers would be appreciated
update 2
My specific flags are (not including warning and include paths - which there are lots)
- Compiler:
-m64 -O2 -g -std=c++17
- linker:
-m64 -O2 -g -rdynamic -lstdc++ -lpthread -lrt -lsystemd -ldl
the main difference with x86 build is that I use flag -m32
instead.
update 3
nm output for nanosleep in libc and libpthread:
[user] ~$ nm -CD --with-symbol-versions /lib/x86_64-linux-gnu/libc.so.6 | grep nanosleep
0000000000130dd0 T __clock_nanosleep@@GLIBC_PRIVATE
0000000000130dd0 W clock_nanosleep@@GLIBC_2.17
00000000000e4760 W nanosleep@@GLIBC_2.2.5
00000000000e4760 T __nanosleep@@GLIBC_2.2.6
[user] ~$ nm -CD --with-symbol-versions /lib/x86_64-linux-gnu/libpthread.so.0 | grep nanosleep
0000000000011d10 W nanosleep@@GLIBC_2.2.5
0000000000011d10 T __nanosleep@@GLIBC_2.2.6
update 4
Precise compiler and linker commands for controller lib:
Note: there are many files, so I will just put in one for as an example - and I will redact some of the include paths to hide project specific details:
Compile
src/bsp_api.cpp
g++ -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wunreachable-code -Wlogical-op -Wshadow -Wmissing-include-dirs -Wparentheses -Werror -Wno-psabi -Wno-error=deprecated-declarations -Wuseless-cast -Wduplicated-cond -Wnull-dereference -Iinc -Iinc/api -m64 -g -fPIC -std=c++17 -fprofile-arcs -ftest-coverage -DRTI_UNIX -DPLANTUML_DDS_TRACE -DNO_MAIN -c src/bsp_api.cpp -o obj/x64Linux_debug/gcov/src/bsp_api.o
Link
gcc -m64 -g -shared -Wl,-soname,libcontroller_library_x64Linuxd.so.0 -lgcov --coverage -o lib/libcontroller_library_x64Linuxd.so.0.2 OBJS_HERE -lstdc++ -lpthread -lrt -lsystemd
Note: this lib does not have rdynamic
- I only use that for executables and not libraries. Note also -lpthread
as pointed out, I will start to update this to -pthread
at a later time.
LDD
[user] controller_library$ ldd lib/libcontroller_library_x64Linuxd.so.0
linux-vdso.so.1 (0x00007ffcc7d5a000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fa2afe25000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa2afc06000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa2af9ee000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa2af5fd000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa2af25f000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa2b0a3a000)
update 5
Searched for all libpthreads on my system. Most of these are cross compiler varients - which are not relevant (and would completely fail at link time due to different arch. The only one I can see that looks "rogue-ish" is ./usr/libx32/libpthread.so
- but that is 32bit. There is only 1 64-bit libpthread on my whole system and its the expected one../
[user] /$ find -name "libpthread.so" 2> /dev/null
./usr/lib32/libpthread.so
./usr/lib/x86_64-linux-gnu/libpthread.so
./usr/libx32/libpthread.so
./opt/trl-imx-scs/5.4-zeus/sysroots/aarch64-poky-linux/usr/lib/libpthread.so
./opt/trl-imx-scs/4.14-sumo/sysroots/aarch64-poky-linux/usr/lib/libpthread.so
./opt/trl-imx-6GTcvr/4.1.15-1.2.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/lib/libpthread.so
./opt/fsl-imx-x11/4.1.15-1.1.1/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/lib/libpthread.so
./opt/fsl-imx-x11/4.9.51-mx8-beta/sysroots/aarch64-poky-linux/usr/lib/libpthread.so
./opt/trl-imx-6GTcvr-PECM/5.4-zeus/sysroots/cortexa9t2hf-neon-poky-linux-gnueabi/usr/lib/libpthread.so
./opt/trl-imx-6GTcvr-PECM/4.14-sumo/sysroots/cortexa9hf-neon-poky-linux-gnueabi/usr/lib/libpthread.so
./opt/trl-ccs-kontron/sdk_v0.1.0/usr/lib/libpthread.so