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
    forums
Old 03-19-2003, 03:40 AM   #1 (permalink)
Travis Dane
Code Monkey
 
Travis Dane's Avatar
 
Join Date: Feb 2003
Location: Netherlands
Posts: 89
Travis Dane is on a distinguished road
Send a message via ICQ to Travis Dane
Post Static Link Library's

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.
__________________
OpenGL, DirectX
Travis Dane is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
setting up static addresses sde Linux / BSD / OS X 16 11-16-2003 09:11 PM
I am a newb, how do you set multiple parts of an image as a link? I sniper baby HTML, XML, Javascript, AJAX 5 02-10-2003 06:40 PM
IP Configuration for Static IP sde Linux / BSD / OS X 4 06-03-2002 05:12 PM


All times are GMT -8. The time now is 08:48 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting