Creating A C Function Library? 
Author Message
 Creating A C Function Library?

This has gotta be a newbie question or a FAQ, but anyway...

I'm looking for a quick introduction to creating my own function
libraries in C/C++. I understand about header files, but I haven't
the foggiest clue about how to go about creating the library that
goes with it. I've used TPU files and Units in Turbo Pascal before,

and that was easy...no #include or anything like that, just a uses
clause.

Anyway, can anybody give me an example of creating a library for
use in future programs just by including the header file? Any
comparisons to the way Units are used in pascal would be helpful.

My C/C++ Compiler is BC++ 3.1

Regards,

       Peter L. Buschman

__________________________________________________________________________

 Peter L. Buschman               ___      
                                (/__)__    "DCL, because Chicks Dig it."


__________________________________________________________________________

 Iota Alpha Chapter - Phi Mu Alpha Sinfonia - Alma College - Alma Mi
__________________________________________________________________________



Fri, 21 Feb 1997 23:47:25 GMT  
 Creating A C Function Library?

Quote:
> This has gotta be a newbie question or a FAQ, but anyway...

> I'm looking for a quick introduction to creating my own function
> libraries in C/C++. I understand about header files, but I haven't
> the foggiest clue about how to go about creating the library that
> goes with it. I've used TPU files and Units in Turbo Pascal before,

> and that was easy...no #include or anything like that, just a uses
> clause.

> Anyway, can anybody give me an example of creating a library for
> use in future programs just by including the header file? Any
> comparisons to the way Units are used in pascal would be helpful.

> My C/C++ Compiler is BC++ 3.1

        Here is the trick. For each library you want to write,
create 2 files : the .h file and the .c (or .cpp) file. Then
compile your .c(pp) file to an object file (.obj) using the IDE
"Compile::Compile to OBJ" menu item.
        Now you have 3 files : the .h, the .c and the compiled
.obj file. To use the library, you need to :

o  #include the .h file in your main .c or .cpp program
o  create a Project file ("Project::Open project" in the IDE)
o  add the .obj and your main .c(pp) files to the project
o  make ("Compile::Make" I believe)

        The principles underlying this are that the "compiler"
is actually a 3-stage process :

1) Preprocess the .c files, by (basically) :
        . copying the #included files into the C/C++ file
        . replacing all calls to macros by their #defined value
        . maybe stripping all comments out

2) Compiling, i.e. producing one .obj file for each .c or .cpp
file (if the .obj file is old or nonexistent)

3) Linking, i.e. producing a .exe file by putting all the .obj
files together.

        Thanks to "make", you can do steps 2 and 3 separately,
i.e. compiling a library to .obj, then linking it to a main
program.

        If you have several related .obj libraries, you may
want to pack them together in a .lib library (using the TLIB
utility). You use the .lib exactly the same way as a .obj.
        Hope this helps.

                                                LudoB.



Sun, 23 Feb 1997 19:20:55 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Newbie: separate big .cs file into small .cs files

2. library function for creating bitmap files

3. Creating Libraries from Functions

4. creating libraries and functions

5. How to create my own function library ?

6. Intialize the list of functions with runtime library common function

7. C function calling function in C++ library

8. Creating edit boxes using create function gives wincore 628 error

9. Creating a .NET managed library to talk to existing unmanaged code

10. Linking library created in VC.NET from VC6.0

11. Creating Libraries

12. Creating Libraries

 

 
Powered by phpBB® Forum Software