How to link static library into static library in Eclipse CDT
I have 3 projects A, B and C. A is开发者_如何学编程 universal and used by B and eventually C. B is a bit more special and up to now only used by C.
Now as I want A and B to be reused as much as possible I thought of both being static libraries.
So I link A and B to static libraries and C to an executable, but when I want to link C
it gives me some undefined reference
errors on A functions. So I added the library A to the linker options to resolve this but it did not help.
So I thought: when I want to deploy B then I also will have to deploy A to be able to link. Is there a way to link the static library A into static library B so I do not have to deploy 2 files?
And if so, how do I achieve this with Eclipse CDT, because I cant find a place where to define additional targets for the archiver.
Addition
I am working under linux but the things should also work under windows. But mainly I need a solution for linux to keep going with the development.
EDIT
Right now I "solved" the problem by linking A and B into static libraries and then use the remaining *.o files to link them into the executable but I do not consider this as good.
change your link order. C use B, and B use A. C does not use A directly, right?
you write:
gcc -o C -lA -lB
it will not work. you write
gcc -o C -lB -lA
it works.
if CDT, you could go to option->C/C++ Build->setting->XXX C linker->Libraries, and change A and B's order.
Another way: use -u option.
see this: http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html BUT, I NEVER succeeded. May anyone tell me how to use -u option?
a static library cannot be linked with another static library. I think because a static library is not an executable code and so full linking process (mainly references resolution) is not done. It's done only for dynamic libraries and executables.
精彩评论