This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to Use Your Own Static Libraries with g++ like the Standard Libraries


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]