Page 1 of 1

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

Posted: Sun Jul 29, 2012 8:36 pm
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

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

Posted: Sun Jul 29, 2012 11:40 pm
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...).

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

Posted: Mon Jul 30, 2012 12:28 am
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...

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

Posted: Mon Jul 30, 2012 1:01 am
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

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

Posted: Mon Jul 30, 2012 1:39 am
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.

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

Posted: Mon Jul 30, 2012 2:29 pm
by Jarod42
Maybe a circular dependencies ?
You can try

Code: Select all

./hasp1.a;./hasp2.a; ./hasp1.a

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

Posted: Mon Jul 30, 2012 4:30 pm
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.

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

Posted: Mon Jul 30, 2012 8:50 pm
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

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

Posted: Tue Jul 31, 2012 12:19 pm
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