Advertisement

Making a Library

Started by November 04, 2001 08:45 PM
2 comments, last by robirt 23 years, 1 month ago
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.
Rodger
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 <stdio.h>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!]
Advertisement
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!
There''s a static library tutorial on the front page, go check it out.
C++, C++, C++

This topic is closed to new replies.

Advertisement