Some general questions about C++ and .lib's (how to make...)

Hi, I have some little general questions.
When you have a block of code which consist mainly of two parts:
->1)initialisation and conversion of input
->2)calculation of a number, which makes use of the initialised and conevrted data
And you have to do the second part 1000's of times;
What is then the fastest way to do that (since it's difficult to make a function with 20 arguments or so...).
I know that you can put it just in a loop, but that's not what I want (I want it to be outside the code).
Can you easily make a lib with two functions (void Init() and Calculate(lots of parameters) from normal code (main()) ? If so, where can I find a tutorial? I searched but didn't find anything usable.

Who is Participating?
rstaveleyConnect With a Mentor Commented:
In the Windows world a .lib is used for static linkage and .dll is used for dynamic linkage.

Your options are as follows:

(1) Distribute your class implementation and header source code (.cpp and .h). Advantages, somebody can choose to compile with different compiler settings than those you chose.

(2) Distribute an object file compiled from your source code with the header (.obj and .h). Advantages (dubious), you keep your source code secret and save the fraction of a second required to recompile it.

(3) Distribute a library for static linkage and your header (.lib and .h). Advantages, you can distribute a whole load of .obj files in a .lib and it should be easy for you client to link the .obj files into his project.

(4) Distribute a dynamic linked library for dynamic linkage (.dll). Advantages, if lots of programs need to use this code at the same time, it saves some memory. Disadvantages - you need to learn some tricks to get up and running with this.

Before you get hung up on libraries, I recommend you make sure you can do (1), which requires the minimum knowledge. It sounds like you are relatively new to C++ and libraries are relatively advanced things to be playing with.

You need to make your code modular so that the required functionality can be moved into another project. You also ought to consider using object orientated design - i.e. wrap your data up into a class - to address the first part of your question. I recommend that you develop a harness module consisting of main(). The harness module includes the header file for your Init() and Calculate() code, which preferably is in a class. The Init() and Calculate() code should be in a separate module (i.e. separate .cpp file) so that you can test it with your harness and then move it to your required project(s) when it is debugged.
You are probably looking at writing a class.


class X {
        // here's the class data...
        // ...
        Init(); // Initialises the class data
        Calculate(); // Runs calclations based on the class data
mrwad99Connect With a Mentor Commented:
>> Can you easily make a lib with two functions (void Init() and Calculate(lots of parameters) from normal code (main()) ? If so, where can I find a tutorial? I searched but didn't find anything usable.

I think what you are after is a DLL.  Read for more info.  You will get the LIB when you compile the DLL.
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

DEEGBALAuthor Commented:
and is this correct:
->a lib is for static linking
->a dll is for dynamic linking
DEEGBALAuthor Commented:
Thanks a lot.
That made a lot clear.
>> Thanks a lot.

Glad to help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.