简体   繁体   中英

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 Bh , 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM