In eclipse I have done the below in windows platform with MinGW compiler - C_proj.exe--->links---->libB_proj.a----->links---->libA_proj.a
When linking A with B I am specifying only the path to libA_proj.a (not the lib name because that is not possible it seems!)
When making use of B inside C I had to specify both the libA_proj.a and libB_proj.a.
Codes -
//a.h
class a
{
public:
void printA();
};
//a.cpp
void a::printA()
{
std::cout<<"This is 'a'"<<std::endl;
}
//b.h
class b
{
public:
void printB();
void printA();
};
//b.cpp
void b::printB()
{
std::cout<<"This is 'B'"<<std::endl;
}
void b::printA()
{
std::cout<<"This is 'B'....calling A"<<std::endl;
a objA;
objA.printA();
}
//c.cpp
int main()
{
b objB;
objB.printB();
objB.printA();
return 0;
}
Now my requirement is -- I don't want to link both B and A with C exe. Is there a way to link only B with C and get the work done so that I can provide only B and C exe to a third party?
A lib-file (or .a file) is a collection of object files - a bit like a zip-file, but with no compression. So you can't really LINK an lib file with another lib file.
What you can do is form one large library from two smaller ones - essentially unpacking and then repacking as one. You use ar -x libfile.a to extract modules, and then you can use ar -a libfile2.a name1.o name2.o to add the object files into the new library.
However, I would just tell the users of your two components to link against both libraries. Much easier solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With