Static lib does not link statically with the libs it's using

General questions regarding the usage of CodeLite
trfillos
CodeLite Curious
Posts: 7
Joined: Tue Jun 12, 2012 2:24 pm
Genuine User: Yes
IDE Question: c++
Location: Greece
Contact:

Static lib does not link statically with the libs it's using

Post by trfillos »

Hello,
First of all, I am using Codelite Rev:5617 build from svn on a fedora 17 machine.
I am trying to make a static library libHasp.a. I have create a project with type "Static Library". In the "Common settings->Linker->Libraries" I have put two other libs (e.g. hasp1.a and hasp2.a) that my library uses And I would like to link them also statically with my library.

My problem is that the created lib (libHasp.a) does not include the other two libs. The build output looks like:

Code: Select all

make[1]: Entering directory `/home/trfillos/codeliteWorkspace/libHasp/libHasp'
g++  -c  "/home/trfillos/codeliteWorkspace/libHasp/libHasp/libHasp.cpp" -g -Wall  -o ./Debug/libHasp.o -I. -I. 
/home/trfillos/codeliteWorkspace/libHasp/libHasp/libHasp.cpp:31:20: warning: ‘hasp_info’ defined but not used [-Wunused-variable]
ar rcus ./Debug/libHasp.a @"/home/trfillos/codeliteWorkspace/libHasp/libHasp/libHasp.txt"
make[1]: Leaving directory `/home/trfillos/codeliteWorkspace/libHasp/libHasp'
Ignore the warning. Shouldn't the ar also include the other libs?

Please I would like your help to make these two libs link statically with my lib.

Thank you very much for your time.

Regards,
Triantafillos
jfouche
CodeLite Guru
Posts: 351
Joined: Mon Oct 20, 2008 7:26 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

Re: Static lib does not link statically with the libs it's using

Post by jfouche »

Hello

I don't think it really answer your question but :
Why don't you link your application with the 3 static lib (libHasp.a, hasp1.a and hasp2.a) ?

Well, I didn't know that we could do a macro static link which embed multible libs (but I never tried...).
Jérémie
trfillos
CodeLite Curious
Posts: 7
Joined: Tue Jun 12, 2012 2:24 pm
Genuine User: Yes
IDE Question: c++
Location: Greece
Contact:

Re: Static lib does not link statically with the libs it's using

Post by trfillos »

jfouche wrote:Hello

I don't think it really answer your question but :
Why don't you link your application with the 3 static lib (libHasp.a, hasp1.a and hasp2.a) ?

Well, I didn't know that we could do a macro static link which embed multible libs (but I never tried...).
Hi,
Actually I tried to select the "Linker is not required for this project" and issue

Code: Select all

ar rcus ./Debug/libHasp.a @"/home/trfillos/codeliteWorkspace/libHasp/libHasp/libHasp.txt" ./hasp1.a ./hasp2.a
by myself from the shell. This makes my job but i was wondering if there is an official codelite way...

Now I am making my job by selecting the "linker not required..." and put the above line to the post build commands.

New Status:
The above way does produce a library big enough to assume that all the libraries are linked together but when I use this library I get undefined references...
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Static lib does not link statically with the libs it's using

Post by eranif »

trfillos wrote:Please I would like your help to make these two libs link statically with my lib.
I just committed a fix to trunk to enable this.

1) do svn up and build codelite
2) In the "Linker" page of the project settings, set in the "LIbraries" the list of libraries you wish to link against as a semi-colon separated list

In your example it should contain:

Code: Select all

./hasp1.a;./hasp2.a
Eran
Make sure you have read the HOW TO POST thread
trfillos
CodeLite Curious
Posts: 7
Joined: Tue Jun 12, 2012 2:24 pm
Genuine User: Yes
IDE Question: c++
Location: Greece
Contact:

Re: Static lib does not link statically with the libs it's using

Post by trfillos »

eranif wrote:
trfillos wrote:Please I would like your help to make these two libs link statically with my lib.
I just committed a fix to trunk to enable this.

1) do svn up and build codelite
2) In the "Linker" page of the project settings, set in the "LIbraries" the list of libraries you wish to link against as a semi-colon separated list

In your example it should contain:

Code: Select all

./hasp1.a;./hasp2.a
Eran
Thank you very much for the fix. I followed your suggestion and recompiled the new codelite so now I am at revision 5650.
I am getting the "correct" build info...

Code: Select all

make[1]: Entering directory `/home/trfillos/codeliteWorkspace/libHasp/libHasp'
g++  -c  "/home/trfillos/codeliteWorkspace/libHasp/libHasp/libHasp.cpp" -g -Wall  -o ./Debug/libHasp.o -I. -I. 
/home/trfillos/codeliteWorkspace/libHasp/libHasp/libHasp.cpp:31:20: warning: ‘hasp_info’ defined but not used [-Wunused-variable]
ar rcus ./Debug/libHasp.a @"/home/trfillos/codeliteWorkspace/libHasp/libHasp/libHasp.txt" "libhasp1.a" "libhasp2.a" 
make[1]: Leaving directory `/home/trfillos/codeliteWorkspace/libHasp/libHasp'
Now I am facing another problem, at my project where I use the above library (libHasp.a) I am getting an undefined reference to a function contained in libhasp2.a. If I link against libhasp2.a also everything is fine but since it is already linked with the above library why do I need to relink it? Anyone knows? Am I doing something wrong?

Thanks again.
User avatar
Jarod42
CodeLite Expert
Posts: 240
Joined: Wed Sep 30, 2009 5:54 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

Re: Static lib does not link statically with the libs it's using

Post by Jarod42 »

Maybe a circular dependencies ?
You can try

Code: Select all

./hasp1.a;./hasp2.a; ./hasp1.a
trfillos
CodeLite Curious
Posts: 7
Joined: Tue Jun 12, 2012 2:24 pm
Genuine User: Yes
IDE Question: c++
Location: Greece
Contact:

Re: Static lib does not link statically with the libs it's using

Post by trfillos »

Jarod42 wrote:Maybe a circular dependencies ?
You can try

Code: Select all

./hasp1.a;./hasp2.a; ./hasp1.a
I will try it when I return back to my home.

I was wondering, if this problem comes from the fact that my library (libHasp.a) is compiled with debug info while the other two libraries I use are release versions.
I will also test that too.
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Static lib does not link statically with the libs it's using

Post by eranif »

trfillos wrote:I was wondering, if this problem comes from the fact that my library (libHasp.a) is compiled with debug info while the other two libraries I use are release versions.
I will also test that too.
I must say, that I never did such thing before. I am not even sure that its possible to link one static library with another...

When I googled it a bit, I could not find nothing that says that it actually works, infact, I only found people who got the same errors as you "undefined symbols"

For example:
http://stackoverflow.com/questions/2157 ... -libraries
Eran
Make sure you have read the HOW TO POST thread
trfillos
CodeLite Curious
Posts: 7
Joined: Tue Jun 12, 2012 2:24 pm
Genuine User: Yes
IDE Question: c++
Location: Greece
Contact:

Re: Static lib does not link statically with the libs it's using

Post by trfillos »

OK I found a solution.

To make a single static library first you have to extract all the other libs then make the new library with ar, out of all the object files.

Thank you all for your help
Post Reply