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

Started by
5 comments, last by CrazyCdn 18 years, 5 months ago
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? :-)
Advertisement
Which compiler are you using?
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")
I'm using Visual C++ 6.0.
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.
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
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...

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

This topic is closed to new replies.

Advertisement