Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: The_GTA on January 24, 2018, 03:21:18 pm

Title: Static Library in Static Library using Code::Blocks?
Post by: The_GTA 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
Title: Re: Static Library in Static Library using Code::Blocks?
Post by: stahta01 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.
Title: Re: Static Library in Static Library using Code::Blocks?
Post by: The_GTA 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
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
Title: Re: Static Library in Static Library using Code::Blocks?
Post by: giorgik 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.
Title: Re: Static Library in Static Library using Code::Blocks?
Post by: oBFusCATed 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.
Title: Re: Static Library in Static Library using Code::Blocks?
Post by: The_GTA 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.