3

I've a problem that drive me crazy. I've an Ubuntu developer machine. I've downloaded a toolkit and I've included it into my C project (eclipse). Well, if I build the project using eclipse on a centos VM the resultant application, copied to the ubuntu system works well. On the centos machine the command make produce at any time a working application.

If I copy the project, including the makefile, on the ubuntu machine and rebuild by means of make command (the makefile doesn't change!!!!!!!) the application built has a "symbol lookup error: .... undefined symbol ...."

the function that is not found is 'declared' (but not implemented) into a library (included into the toolkit, not my production!!!) and implemented into another library (always into the toolkit clearly).

WHY???? And Above all, how to fix? I should include also these dynamic libraries at linking time? (but the makefile is the same!)

same makefile two differents OS, make doesn't work tow differents OS, copied application and relevant libraries, it works

Thanks a lot... one beer (in Bremen)to who makes me understand where I'm doing a ...

I add more details:

cmd (same on ubuntu and centos):

gcc -L/home/andrea/put/lib -o "put" ./main.o -ltrek_toolkit_ds_api -ltrek_toolkit_common_api -ltrek_toolkit_cfdp_api -lcfdp_plus -lrt

gcc versions:

gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4 [NOT WORKING]
gcc (GCC) 4,8,3 20140911 (Red Hat 4,8,3-9) [WORKING]

ldd put on Ubuntu:

    linux-vdso.so.1 =>  (0x00007ffd26b15000)
libtrek_toolkit_ds_api.so.0 => not found

libtrek_toolkit_common_api.so.0 => not found

libtrek_toolkit_cfdp_api.so.0 => not found

librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f23d29cb000)

libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f23d2606000)

libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f23d23e8000)

/lib64/ld-linux-x86-64.so.2 (0x00007f23d2bd3000)

ldd put on Centos:

linux-vdso.so.1 =>  (0x00007fffdd569000)

libtrek_toolkit_ds_api.so.0 => not found

libtrek_toolkit_common_api.so.0 => not found

libtrek_toolkit_cfdp_api.so.0 => not found


libcfdp_plus.so.0 => not found
<--- !!! this is the difference !!!

librt.so.1 => /lib64/librt.so.1 (0x00007f158e0c9000)

libc.so.6 => /lib64/libc.so.6 (0x00007f158dd08000)

libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f158daec000)

/lib64/ld-linux-x86-64.so.2 (0x00007f158e2fb000)

tryed on Ubuntu (doesn't work naymore):

gcc -L/home/andrea/put/lib -o "put" ./main.o -ltrek_toolkit_ds_api -ltrek_toolkit_common_api -ltrek_toolkit_cfdp_api -Wl,--whole-archive -lcfdp_plus -Wl,--no-whole-archive -lrt

Error:

./put: symbol lookup error: /home/andrea/put/lib/libtrek_cfdp_device_api.so: undefined symbol: register_printf_debug

"register_printf_debug" is included in library cfdp_plus, that is included when built on centos and not when built on Ubuntu.

So, how to tell to the linker to do its job and to include this library?

  • Send the beer first, that is what give me inspiration. :) I am just kidding, I looks the part of the things that I do not understand well. Usually when you try to reproduce error on a minimal setup, you most of the time see the mistake. – innoSPG Jul 31 '15 at 02:24
  • actually I'd like to understand if gcc works differently between centos and ubuntu. the minimal environment is ubuntu, shell, makefile generated (and working) by eclipse... but it gave the undefined symbol error! – Andrea Costantino Jul 31 '15 at 07:16
  • Hey C builders! Maybe I found the problem. when I list the libray (ldd) on centos (working environment) I got that my application include the library (dynamic in any case) that define the missing function. When I do the same on ubuntu I found that this dynamic library is missing!!! So, why gcc on ubuntu is not including this library? And how to force this sh... linker to do its job??? – Andrea Costantino Jul 31 '15 at 08:17
  • Don't use whole-archive, it isn't what it is for. Set correct LD_LIBRARY_PATH and re-run `ldd`, it lookups recursively and without correct path results aren't telling anything. Move `-lcfdp_plus` to be before `-ltrek_toolkit_cfdp_api` - if I unerstand dependencies correctly. Check there are no more of these libraries exists in file system. Check `.so` of your libraries are symlinks to correct `.so.0`. If everything else fails - consider using `LD_DEBUG`. – keltar Jul 31 '15 at 09:21
  • Thanks keltar. The library that depends on cfdp_plus is libtrek_cfdp_device_api, not the toolkit... I tried to put in any position cfdp_plus, nothing change! Please consider that the same gcc cmds on centos work well! and produce an application that copied on Ubuntu works well. Compilation on Ubuntu, using the same makefile produced by eclipse on Centos doesn't work. Eclipse on Ubuntu, configured as for Centos doesn't work too!!! All requested libraries are correctly found. The only differences I see are: gcc version (newer on ubuntu) and ldd results (Centos includes cfdp_plus, Ununtu don't) – Andrea Costantino Jul 31 '15 at 10:09
  • @AndreaCostantino yes but it links well, your problem appears only after running resulting binary. Which means linker found everything required. Check `gcc -dumpspecs` on both systems; look for `--as-needed` linker flag here. Try adding `--no-as-needed` before `-l`'s. Try running binary with `LD_PRELOAD=lib/libcfdp_plus.so.0 ./put` (just to make sure it works well). Please add results to the question. – keltar Jul 31 '15 at 10:23
  • Tried LD_DEBUG=libs... all libraries are correctly found. on Centos it loads the cfdp_plus. on Ubuntu don't. As aspected due the ldd commands shows that the cfdp_plus is not included... how I can say to this b|t@h linker to include this library??? why on centos it does this and on ubuntu it doesn't? why even if it is in the -l list I don't find it in the ldd results? The problem is that it's like a 'private' library, so I haven't any prototype to include in my main (doing nothing) and to force the application to load this library... otherwise I'll do it by means of dlopen (good idea... I try) – Andrea Costantino Jul 31 '15 at 10:23
  • Yessss keltar, using LD_PRELOAD it works... ok... it is not an elegant solution. in the worst case I'll use it. but at this point my question is still the same: why the built application give two differents results to ldd if built using ubuntu or centos? – Andrea Costantino Jul 31 '15 at 10:26
  • Have you checked `gcc -dumpspecs | grep as-needed` on both systems? What was the results? If that wouldn't give any ideas, try adding `-###` gcc flag (it will dry run - print commands instead of actually executing them) and comparing output. My best bet is still wrong `--as-needed` flag hidden somewhere in system's gcc config. – keltar Jul 31 '15 at 13:16

0 Answers0