Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    cpp
  » Static Link Library's
      by Travis Dane
 Page 1 of 1 
   

(Login to remove green text ads)
No doubt if you are programming for a while and your programs keep getting bigger and bigger you wondered, Might there
be a way to compress all the Functions, Structs and Classes into 1 file, Easy and quick for use.

When you want to accomplish this, Using Static Link Library's, Would be a good idea.

Static Library's are , As stated above, Big collections of Functions and other things all in 1 file.
Static Library's are linked to the program at Compile-Time, So the user doesn't need to have the Library to run it.

Creating Static Link Library's with VC++ 6.0:

Quote:
Create a new Project, Select as type of the Project "Static Link Library", That's it.
Creating Static Link Library's with VC++ .NET:

Quote:
Create a new Project, Select as type of the Project "Win32 Application", Go to "Application Settings", Select "Static
Library" and de-select "precompiled headers", you can get rid of the "Readme.txt" file in your Project.
Now to create a function to be stored in the SLL (No need for a main() here since there isn't an Entry-Point):

Code:
int Addition(int first,int second) { return first+second; }
Now compile it and we have a SLL to use.

Now we have a SLL to use we can create a program that's going to use it, For this you can just create any application
you want to (Console,Win32):

Code:
#pragma comment(lib,"test.lib") /* Here we tell the compiler to link up with "test.lib" during the linking, Assuming you called it "test.lib", We could configure this in the Compiler options but doing it in the source code ensures for a better portability between compilers */ #include <iostream> // Include the newest input-output stream header #include <conio.h> int Addition(int first,int second); /* Here we declare our function that resorts in the library because the compiler needs to know it exists since it doesn't see it's definition until liking up with the "test.lib". */ using namespace std; // So we won't have to specify this namespace to use it's functions int main(void) // The program's entry point { cout << Addition(2,4) << endl; getch(); // Prevent the program from exiting premature return 0; // Return succes }
That wraps it up, That wasn't too hard no was it? SLL also gives you the benefit (???) of keeping your source code hidden
from others since it's already compiled.

Next Tutorial i'll have a go at explaining Dynamic Link Library's wich give you an advantage over the SLL.




 
 Page 1 of 1 
   

Rate This Article
1 2 3 4 5 6 7 8 9 10





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle