Author Topic: Static Library in Static Library using Code::Blocks?  (Read 773 times)

Offline The_GTA

  • Single posting newcomer
  • *
  • Posts: 8
  • Developer
    • Magic.TXD
Static Library in Static Library using Code::Blocks?
« on: January 24, 2018, 03:21:18 pm »
Hello Code::Blocks crew,

I have the same problem as described here:

http://forums.codeblocks.org/index.php/topic,11522.msg78462.html#msg78462

Under MSVC I am able to include static libraries in static libraries, but I cannot do so with Code::Blocks. But GNU tools support it!

Did you know that GNU AR supports "thin libs" using -T option so which basically contain file paths to all objects and .a files? This way static libraries can include other static libraries.

(https://stackoverflow.com/questions/3821916/how-to-merge-two-ar-static-libraries-into-one , the answer by Guillem Lover)

Unfortunately even with Code::Blocks big scripting system I cannot find a way to add options to the ar command line. But I would prefer that Code::Blocks looked into the Linker options of static library projects and used a thin-lib output if the project were to add other static libraries...

Please help..

- Martin

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6278
    • My Best Post
Re: Static Library in Static Library using Code::Blocks?
« Reply #1 on: January 24, 2018, 05:36:54 pm »
Do you know your Operation System name and version?
Do you know your Compiler name and version?
Do you know the linking command that you wish to use in Code::Blocks?

If you know the above are you not telling us for a valid reason?

Edit: Did you try adding "-T" without the double quotes to the Linker other options?

Tim S.
« Last Edit: January 24, 2018, 05:39:15 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Testing, compiling CB Trunk against wxWidgets 3.0.2.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline The_GTA

  • Single posting newcomer
  • *
  • Posts: 8
  • Developer
    • Magic.TXD
Re: Static Library in Static Library using Code::Blocks?
« Reply #2 on: January 25, 2018, 12:34:56 am »
Do you know your Operation System name and version?
I am using Linux Ubuntu 17.10 Artful.
 
Do you know your Compiler name and version?
GCC 7.2.0

Do you know the linking command that you wish to use in Code::Blocks?
gcc -r -s -T ../lib/linux/Debug/libfs.a *ALL OBJECT FILES*
gcc -r -c -T ../lib/linux/Debug/libfs.a ../../zlib/lib/linux/Debug/libzlib.a

If you know the above are you not telling us for a valid reason?

Edit: Did you try adding "-T" without the double quotes to the Linker other options?

Tim S.
I have actually managed to fix it by changing the GCC global compiler advanced options. The behavior of "Linking objects to static libraries" was changed. The new script is...

Code: [Select]
rm -f $static_output
$lib_linker -r -s -T $static_output $link_objects
$lib_linker -r -c -T $static_output $link_options

Since static libraries do not use the $link_options otherwise, I can just add all the paths to static library dependencies in the "Build options..." -> "Linker settings" tab -> "Other linker options" editbox. Kind of a hack but it works so I am fine with it. Just that everyone who would want this support has to adjust Code::Blocks global settings... kinda bad.

Here is a step-by-step guide (with images): http://green-candy.osdn.jp/codeblocks_config.html

- Martin
« Last Edit: January 25, 2018, 01:14:20 am by The_GTA »

Offline giorgik

  • Single posting newcomer
  • *
  • Posts: 1
Re: Static Library in Static Library using Code::Blocks?
« Reply #3 on: January 26, 2018, 11:14:00 am »
Also I have the same problem of compiling using 2 static libraries of which one calls the other. I use Code :: Blocks 16.1 with the MinGW 7.1 compiler from MSYS2 on Win7 64bit.
If it can serve, I can attach the whole project to it: the 2 static libraries and the test main that uses them.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10954
    • Travis build status
Re: Static Library in Static Library using Code::Blocks?
« Reply #4 on: January 26, 2018, 08:41:02 pm »
Also I have the same problem of compiling using 2 static libraries of which one calls the other.
I doubt you have the same problem. But you have to share details about your problem to be sure.
The op has posted how to change the compiler settings to make it possible to merge static libs.

If it can serve, I can attach the whole project to it: the 2 static libraries and the test main that uses them.
Just link both libraries in the final executable/dll/shared library. This is the standard way of linking to static 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 The_GTA

  • Single posting newcomer
  • *
  • Posts: 8
  • Developer
    • Magic.TXD
Re: Static Library in Static Library using Code::Blocks?
« Reply #5 on: January 27, 2018, 02:53:14 am »
Also I have the same problem of compiling using 2 static libraries of which one calls the other. I use Code :: Blocks 16.1 with the MinGW 7.1 compiler from MSYS2 on Win7 64bit.
If it can serve, I can attach the whole project to it: the 2 static libraries and the test main that uses them.
If you want the same solution that I used for the problem it should work, as long as you use the GCC compiler, even on Windows. Could assist you if you want, global compiler settings have to be changed by yourself ofc.