Sign in to follow this  
Maxkarlstedt

How do I write my own libary-file?(.lib)

Recommended Posts

Hi I wonder how I can write my own .lib files that includes functions so I can eaisly just type them in a .cpp file like this "CountPlus(argument 1, argument 2);" and it looks up in the .lib file I wrote to send a return value. Doing this to get rid of writing the CountPlus() function everytime I wanna have it a program. Now when you heard my wishes, is this possible or am I asking the wrong questions about making .lib files? :-)

Share this post


Link to post
Share on other sites
A .lib file is definitely something you want to consider.

To build one, start a new project in Visual Studio and choose static library. (DLL is another option, although slightly more complicated)

You write a static library like any other file, define your functions/classes in a header and implement them in a .cpp file.

When you choose build, you will now have a .lib file in the /debug folder.

Then you can include your .H file in any program and link the library

#pragma comment(lib, "Mylibrary.lib")

Share this post


Link to post
Share on other sites
Quote:
Original post by Kalasjniekof
a bit off-topic, but you should download the new Visual C++ 2005 Express version. It's completely free (for the first year) and complies better to the standards.


Let me clarify... it is free to download for 1 year. After that year, those who haven't downloaded it yet, have to pay (call it a tax for being dumb). The license you get is valid forever no matter if you download it now for free or pay for it later.

Luck!
Guimo

Share this post


Link to post
Share on other sites
Why not write it once in a .h/.cpp file and just include the header... Done. Instead of linking in a lib and the header file. Same amount of work from a new project stand point but doing it my way is faster to get it going. Unless you plan to include a ton of other .h/.cpp files in the .lib...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this