Search code examples
clinkershared-librariesstatic-librariesinclusion

Undefined symbols in a shared library compiled with a static library


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.


Solution

  • 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.