0

I have a problem with linking together different libraries using it in one executable project.

Let's say Project A contains a function named foo(); It is compiled as a static library.
Project B contains a function named bar(), includes a header from A and compiled as a shared library with -Wl,--whole-archive libA.a -Wl,--no-whole-archive flags.
libB.so was moved to /usr/lib.

Now, project C includes B.h, calls bar(), but wasn't compiled due to the reason of undefined reference to foo() function, which was defined in project A.

nm libB.so says:

U foo

I am using gcc, the programming language is C, the IDE is Eclipse CDT.

Is anyone who has an idea or tip to solve this problem?

Thank you.

Chandru
  • 1,306
  • 13
  • 21
Balázs Kreith
  • 141
  • 2
  • 8
  • what does "nm " says? – Icarus3 Jul 24 '14 at 11:57
  • @Icarus3: It says T foo() – Balázs Kreith Jul 24 '14 at 14:38
  • That's good. Now can you grab the gcc command line for building shared object? The reason I am asking because, I tried this at my end and "nm " shows "T foo". So there has to be something weird going on while building the shared object. – Icarus3 Jul 24 '14 at 14:50
  • @Icarus3 Here it is: gcc -Wl,--whole-archive /usr/lib/libA.a -Wl,--no-whole-archive -shared -o "libB.so" ./sys/sys_confs.o ...further object files... ./mpt_srvlib.o -lssl -lm -lrt -lpthread – Balázs Kreith Jul 24 '14 at 15:02
  • Sorry, I am unable to reproduce this at my end. Just for the information I am using gcc-4.8.2. – Icarus3 Jul 24 '14 at 15:25

1 Answers1

0

Thanks to Icarus3 for his contribution, the problem is restricted.

Some functions in ProjectA used restrict keyword, thus it was compiled with -std=gnu99. It turns out that eliminating this keyword from the code and the -std=gnu99 from the compiling command eventually solved the problem.

Balázs Kreith
  • 141
  • 2
  • 8