#### Archived

This topic is now archived and is closed to further replies.

# Making a Library

## Recommended Posts

robirt    127
I wanted to make something into a reusable static library. I compiled the library, and apparently, i need some kind of include file as well to go with it in my project sing the library. Can someone give me info on how i would make that include file. I just want to be able to access the functions and stuff in the library. Also, I''m just making this into a library for the heck of it. Could someone tell me the advantages and disadvantages of making it a library instead just a bunch of extra source code.

##### Share on other sites
Null and Void    1088
The main reasons to make something into a static library are (a) if there are a bunch of source files and you want to make it easier to link to a project and (b) if you don''t want people seeing your source code. Here''s an example of a source and header pair:
  // Fish.cpp#include "Fish.h"void Fish(void) { printf("Fish\n");}// Fish.h#include extern void Fish(void);

You compile that into a static library, then include Fish.h in whatever source file needs to access the functions in the library.

[Resist Windows XP''s Invasive Production Activation Technology!]

##### Share on other sites
Oluseyi    2112
quote:
Original post by robirt
Can someone give me info on how i would make that include file. I just want to be able to access the functions and stuff in the library.

Are the functions in your library declared in headers and defined in implementation files? Then you can just distribute those headers with your library (you can optionally remove the private data in them).

quote:
Also, I''m just making this into a library for the heck of it. Could someone tell me the advantages and disadvantages of making it a library instead just a bunch of extra source code.

Compile time. If it was a dynamic link library, you''d also gain memory usage - several applications could use the same library, and an application could "unload" the library as soon as it was done. Of course, if one app was done and another wasn''t, the first wouldn''t actually unload the library. Think of it more as a request to unload.

I wanna work for Microsoft!