I'm making a bunch of libraries to use in my programs and some of my libraries depend on other libraries, so I compile them using the -l option of gcc to link the dependencies and it works fine but there is one case where I have a problem :
- Let's say I make a library called lib1 with some basic functions.
- I then make lib2 with functions that sometimes call lib1 functions.
- Finally, I make a program that uses a function from lib2 which depends on a lib1 function (let's say I have a custom strcpy in lib2 that needs a custom malloc from lib1)
Having done that, I try to compile my program with gcc -llib2 (assuming lib2.a contains lib1 functions if I understood how static libraries work) but it doesn't work because the function from lib2 needs a function from lib1 that the compiler doesn't find. I guess I actually need to do gcc -llib1 -llib2 but it seems useless since lib2 already should contain lib1 functions.
Is there any way I could compile my program without specifying every library in the gcc command line ? (assuming I will have more than 2 libraries and multiple layers of dependencies)
I found this answer https://stackoverflow.com/a/41323069/12136455 that seems to shed some light on my problem but I can't quite understand what he means.