My Stuff
Username

Password

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


Static Link Library's


No votes yet

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):

 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):

 #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.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You can use BBCode tags in the text.
  • You can enable syntax highlighting of source code with the following tags: [code], [blockcode], [asp], [awk], [c], [cpp], [csharp], [drupal5], [drupal6], [java], [javascript], [jquery], [mysql], [perl], [perl6], [php], [python], [ruby], [sql], [vb], [vbnet], [xml].
  • Use to create page breaks.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.