Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: MC on June 20, 2014, 05:22:50 pm

Title: Add .o files to static library
Post by: MC on June 20, 2014, 05:22:50 pm
I have several own written functions where all related ones share the same project.
These functions are compiled with .exe as target so that i can test the functions using main.cpp.
Every .cpp file is compiled to a .o file before linking takes place.
Another project called MyLib should combine all the .o files of the other projects into one library file.
For this project, the target is "static library". However if i add the .o files from the other projects using
build options -> linker settings -> link libraries they will not be included in the generated static library libMyLib.a.
My workaround at the moment is to add all .cpp files from the other projects to the MyLib project, which is quite
unsatisfactory.
Additionally i would like to continue using an own MyLib project so that i must not tell each single project of
each set of library functions the path of the libMyLib.a file which would cause problems if the library path changes.
 
My question is how can i compile my library functions, test them in their own project and link all the .o files into one superseeding library
with another project.
 
Thank you !
Title: Re: Add .o files to static library
Post by: Aleksandr on June 20, 2014, 08:57:46 pm
Why do not you do one project containing all the source files and several different targets?
Title: Re: Add .o files to static library
Post by: MC on June 20, 2014, 10:52:45 pm
Each set of library functions is developed independently and it should stay so.
Title: Re: Add .o files to static library
Post by: MC on June 21, 2014, 04:16:40 pm
Solved!
Use Settings->Compiler->Other Settings->Advanced Options->Link Object Files to Static Library and add
$libs to the cmdarg for the linker.
Then i can link objects and/or libs from other projects into one big library file.

Needed a little fiddling to find that out.  ::)