Author Topic: Include a static lib into another ?  (Read 10794 times)

Offline Kalith

  • Multiple posting newcomer
  • *
  • Posts: 67
Include a static lib into another ?
« on: November 15, 2009, 01:29:14 pm »
Hi there !

Yesterday, I had to compile some static library (OIS, for mouse and kb input) working with DirectInput (which is a static lib too). It compiled fine, but when I included it in my project, I had to link to the DirectInput library also.
That didn't please me, so I searched for a way to "include" DirectInput into the OIS library.

I managed to do it with the command line, by extracting the content of the DInput lib and using "ar" to archive it with the OIS object files. It works fine, but I was wondering if there was a way to do this directly in Code::Blocks ?
I mean, when building a static library, it seems that Code::Blocks doesn't look at the additional libraries provided in the project's build options. I guess this is a normal behavior, considering a static library is only linked when building an executable or a DLL (if I understood it well...), but couldn't these be plainly "included" in the resulting library ?

I've compiled OIS with Visual C++ also, and in this IDE they have an "additional dependencies" field where you can put other libs to be included in the resulting one.

Hope I was clear, and thanks for you help.

Offline Kalith

  • Multiple posting newcomer
  • *
  • Posts: 67
Re: Include a static lib into another ?
« Reply #1 on: November 25, 2009, 07:14:14 pm »
I don't like bumping threads, but I though this was an easy answer :) Nobody ?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Include a static lib into another ?
« Reply #2 on: November 25, 2009, 07:24:40 pm »
What Compiler/Linker?
Add the needed options needed to the extra linker settings.

If added steps, add the steps to post step.

You used a lot of words to give very very little information.

Tim S.

« Last Edit: November 25, 2009, 07:26:13 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Kalith

  • Multiple posting newcomer
  • *
  • Posts: 67
Re: Include a static lib into another ?
« Reply #3 on: November 25, 2009, 08:31:19 pm »
I'm using g++ and its default linker (ar.exe).
I've configured CB to display the build log in full command line, and if I add a custom command to the linker by using the project's "Build options -> Linker Settings -> Other linker options", it doesn't show up.
Same thing if I add a library to link with.

It's like CB "forgets" the linker options when compiling static libraries (of course, everything works fine when compiling DLLs or executables).

Quote
You used a lot of words to give very very little information.
English is not my native language, I apologize...

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Include a static lib into another ?
« Reply #4 on: November 25, 2009, 09:05:19 pm »
It's like CB "forgets" the linker options when compiling static libraries (of course, everything works fine when compiling DLLs or executables).

What version/SVN of Code::Blocks?
This issue of forgetting settings happened to someone else; may be a bug in Code::Blocks.

What is the exact option you put in extra settings?
Certain ones go away because they should be put in regular option section.
The rules to make them go away might be wrong, changed or need fixing.

Tim S.
 
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Kalith

  • Multiple posting newcomer
  • *
  • Posts: 67
Re: Include a static lib into another ?
« Reply #5 on: November 25, 2009, 10:53:08 pm »
I'm using the latest nightly build.

About the option I set, it doesn't matter : whatever I type doesn't appear on the command line. I don't really get it.

But what really matters to me is that I can't link a static library with another.
I can link a static lib to a dynamic lib or to an executable, but not to another static library. Is this the way it is supposed to work ?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Include a static lib into another ?
« Reply #6 on: November 25, 2009, 11:06:57 pm »
[quote author=Kalith link=topic=11522.msg78754#msg78754 date=1259185988
But what really matters to me is that I can't link a static library with another.
I can link a static lib to a dynamic lib or to an executable, but not to another static library. Is this the way it is supposed to work ?
[/quote]

I have no idea; never tried to embed one static library inside another using MinGW GCC.

If you do not know if it is possible or the command line that does do it, I see no reason to think it is a Code::Blocks issue. Without a way to duplicate the problem with Code::Blocks forgetting options it is not worth my time to even try to see if the problem exist. I tried it with the Nov 11 Nightly build from file CB_20091111_rev5911_win32.7z

Tim S.

 
« Last Edit: November 25, 2009, 11:32:50 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Include a static lib into another ?
« Reply #7 on: November 25, 2009, 11:13:04 pm »
I'm using the latest nightly build.

This is NOT an answer!!!

An SVN or Date is needed for it to be an answer that I can trust!

I wasted too much time in the past where the user missed an nightly build. I want real data.

Tim S.

It saves options for me. Using SVN 5911 Date: Nov 11 2009
Code
mingw32-gcc.exe -Wall -testtim4  -g     -c C:\TimS\testc\main.c -o obj\Debug\main.o
mingw32-gcc.exe: unrecognized option '-testtim4'
mingw32-g++.exe  -o bin\Debug\testc.exe obj\Debug\main.o   -testtim5  
mingw32-g++.exe: unrecognized option '-testtim5'
« Last Edit: November 25, 2009, 11:33:51 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Kalith

  • Multiple posting newcomer
  • *
  • Posts: 67
Re: Include a static lib into another ?
« Reply #8 on: November 26, 2009, 10:34:14 pm »
Wow, I appreciate your help and understand your point, but there's no need to be so rude :)
I do have the latest nightly (rev 5911), and from the example you give, it seems I've been very unclear about my problem...

Here is a simplified view of my situation :
  • Main Project : compiles "test.exe", requires "mylib.a"
  • MyLib Project : compiles "mylib.a", requires "otherlib.a"
If I want to build "Main Project", I need to include both "mylib.a" (which is perfectly normal) and "otherlib.a", which is not a direct dependency.
I'd like to avoid this problem by including "other.a" directly into "mylib.a", and I simply don't know how... because if I add "otherlib.a" to the "Link library" of "MyLib Project", Code::Blocks ignores it.

I know I'm not trying to do something crazy, because it can be done in Visual C++.
Maybe this can't be done with the GNU compiler/linker ?

Thanks again for your help anyway !

Edit : and whoops, I overlooked your first post.
I wasn't saying this is a Code::Block issue, I'm just asking if it can be done or not ;)
« Last Edit: November 26, 2009, 10:36:34 pm by Kalith »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Include a static lib into another ?
« Reply #9 on: November 27, 2009, 10:21:19 am »
.a files are just an archive with bunch of objects files (.o), there is no dependency info in them, unfortunately.

This one can be fixed if CB is modified to add -l/-L options to the final executable's/sharedlib's link commands.
But there might be problems with the order of the libs :(
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Kalith

  • Multiple posting newcomer
  • *
  • Posts: 67
Re: Include a static lib into another ?
« Reply #10 on: November 29, 2009, 09:35:47 pm »
I asked the same question on a french board, and it confirms what oBFusCATed said : this is not possible with GCC.
Thanks anyway to both of you !