On Wed, Jun 29, 2011 at 5:51 PM, Jonathan Wakely <jwakely.gcc@xxxxxxxxx> wrote: > On 29 June 2011 22:11, GM wrote: >> I have my own libraries I've written in C++. So for instance, I have >> written "cartman.h" and "cartman.cpp" and I have managed to end up >> with "cartman.h" and "libcartman.a" for use in my own programs. >> >> The issue I'm having is that I would like to be able to use my own >> libraries in the same manner as I can use the standard C++ libraries. >> >> If I do something like... >> >> #include <iostream> >> #include <vector> >> >> ....then when I compile my program, g++ auto-magically finds the >> correct libraries and links them up with my code. > > I should point out that there's no magic here, the entire C++ standard > library is in two libraries, so g++ always links with -lstdc++ > -lsupc++ and that gets you everything. > > There's no libiostream.a or libvector.a etc. which get linked to > depending which headers you've included. > > (Also, <iostream> and <vector> contain mostly templates, so there's > very little code that needs to be linked in for them anyway.) > > If you want to use your own libraries in that way, you'd have to have > a single large library, not lots of small ones, but maybe working in > the same manner as you can use the C++ standard libraries is not > really what you want. That's why I suggested the makefile-based > solution. > Thanks very much for the answer! I think that all made sense - thanks for the education. If I did want to use one large library, in the manner of the C++ standard libraries, then I think I would use the "ar" command to lump all the cartman.o, kenny.o, stan.o, and etc. files into one large "libmega.a". Then I'd still have separate header files I'd include as necessary. So I'd perhaps #include "kenny.h" and #include "cartman.h" and then just link with "-lmega" and be done with it. Is that all correct? What disadvantages are there to doing that versus having lots of small libraries (libcartman.a, libkenny.a, libstan.a, etc.) and linking to them individually as you first suggested? Would my program get bloated by having all of libmega.a included as part of the executable, or do only the parts of the library actually used get linked in anyway?