# C++ static library creation

## Recommended Posts

MajinMusashi    182
Hi! I've created a text rendering engine (wrapper?) based on Sven Olsen FreeType tutorial (Nehe - Lesson 43). It works good at the moment, and I feel now is the time to pack it into a static library (since I'm using the same classes on some different projects). But man, I have so many questions. Please, take a look at the source and/or the image (overall library design) below: Source files Overall library design (the way the classes are arranged) - please interpret the arrows simply as "using" 1) As you can see from the image above, only "C_TextSingle" and "C_TextMulti" (both inherited from "C_TextBase") must be instantiable to the library users. How can I do that limitation? 2) Every header file (5) must be provided along with the library file or can I reorganize it so the user needs to include only one header file + library file (highly desirable)? The problem gets even worse because this library is a wrapper for the FreeType2 library (one library file + some headers) and uses SDL + OpenGL (two library files + many headers); Thanks a lot! I have found almost nothing on Google about more complex static libraries :( PS.: "C_FontManager" is a singleton; PS.: I'm using Visual C++ 6.0 + SDL + OpenGL + FreeType2

##### Share on other sites
This might be more of a tip for when exporting to a library format then a solution to your problem. You should probably namespace you classes/objects so that when you eventually distrubute them they don't have variable and type name conflicts.

##### Share on other sites
njpaul    367
I usually just change the configuration of the workspace to a .lib in the general tab (in .NET) and I haven't had a problem yet. I don't remember if you need to include every header file (just a guess, I'd say yes). Someone correct me if I'm wrong. And namespaces are definately a good practice to get into.

##### Share on other sites
MajinMusashi    182
Quote:
 Original post by njpaulI usually just change the configuration of the workspace to a .lib in the general tab (in .NET) and I haven't had a problem yet.

No problem here. I know how to set up Visual C++ so it will generate a .LIB. I'm confused about the "internals" :)
Thanks anyway!

##### Share on other sites
MajinMusashi    182
Come on, guys! Help me...
By the way, I've found a trick to make some classes instantiable/reachable only inside/by some specific classes, what answers my second question. Example:
// Class A must be instantiable only by class Bclass A {private:    A();public:    draw();friend class B;};// Class B is the only one that can instantiate Aclass B {private:    A a;};int main() {    A a;  // ERROR - A constructor is private!}

Thanks, and please, give me some light about C++ static libraries :(