Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Create and use a library

Reply
Thread Tools

Create and use a library

 
 
Gattaca
Guest
Posts: n/a
 
      06-09-2004
Hello,

1. How can I create a personnal library (with my own functions) ?
2. How can I use it ?
I know that in my source code I will have something like
#include "mylib.h"

But how to make a link between mylib.h and the library compiled ?

Thanks

Note that I read the FAQ first. I didn't find answer to my questions.
 
Reply With Quote
 
 
 
 
Case -
Guest
Posts: n/a
 
      06-09-2004
Gattaca wrote:
> Hello,
>
> 1. How can I create a personnal library (with my own functions) ?
> 2. How can I use it ?
> I know that in my source code I will have something like
> #include "mylib.h"
>
> But how to make a link between mylib.h and the library compiled ?


a. Place all functions in a file with name "mylib.c".
b. Place all function declarations and other stuff (types,
macro's, #defined constants, ...) in the "mylib.h".
c. As you say, #include "mylib.n" in every source that
uses one or more of these library functions.
d. Compile "mylib.c", "source.c", ...
e. Link the object files into a program.

Step d. and e. can be done with one action/command for example:

cc source.c mylib.c -o myprog

This will invoke the linker as well. When you compile "source.c"
the compiler sees there are external functions (declared in "mylib.h")
and marks calls to them as unresolved. The linker makes a list
of all these unresolved externals and tries to find a match in
all object files it currently is processing. When there's a
match it fill in the right 'address' for each external.

HTH

 
Reply With Quote
 
 
 
 
Gattaca
Guest
Posts: n/a
 
      06-09-2004
Gattaca a écrit :
Sorry but I assume I was not clear enought.
When I said I wanted to create a personnal library It was rather
-> How can I create a personnal compiled library (not a C file)?
In order to keep my source code secret and to do "a public interface"
with a "mylib.h" header file.

Thanks


> Hello,
>
> 1. How can I create a personnal library (with my own functions) ?
> 2. How can I use it ?
> I know that in my source code I will have something like
> #include "mylib.h"
>
> But how to make a link between mylib.h and the library compiled ?
>
> Thanks
>
> Note that I read the FAQ first. I didn't find answer to my questions.

 
Reply With Quote
 
Andrew
Guest
Posts: n/a
 
      06-09-2004
On Wed, 09 Jun 2004 16:32:24 +0200, Gattaca <(E-Mail Removed)>
wrote:

>Gattaca a écrit :
>Sorry but I assume I was not clear enought.
>When I said I wanted to create a personnal library It was rather
>-> How can I create a personnal compiled library (not a C file)?
> In order to keep my source code secret and to do "a public interface"
> with a "mylib.h" header file.
>


[snip]

You would be better off asking this question in a vendor-specific
group, as Standard C has no concept of a "personnal library".

To point you in the right direction, you need to check your
implementation's documentation on its library manager (for MSVC this
is "lib.exe", for GNU C this is "ar"). You use the library manager to
collect all the object files generated from your TU's into one big
file. To use it, you need to let your linker know that it can check
out said library for otherwise unresolved references. Again, this is
implementation specific, and is entirely off-topic here.

--
Andrew

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Api to create document and add,edit,delete text and t Krithika San Ruby 3 11-14-2009 09:29 PM
How to use template to create a library. Sunny C++ 5 03-30-2007 02:11 PM
Create c++ library for use in C TBass C++ 5 04-04-2006 01:23 PM
Re: Difference between Web Control Library and Class Library Alan Ferrandiz [MCT] ASP .Net 0 09-11-2004 01:51 PM
Re: Difference between Web Control Library and Class Library Mythran ASP .Net 0 08-24-2004 05:53 PM



Advertisments