C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-13-2002, 06:19 AM   #1
Unregistered
Guest
 
Posts: n/a
How to create a library

Hi there,
I'm a newbie in C and I made some functions, but now I wanna use them as libraries.
I create a function corr() in a file corr.c and corr.h and compile that with:
gcc -c corr.c -o corr.o. Now everytime I need to use my function on a program I have to write include the line #include <corr.h> and then type

gcc corr.o myprog.c -o myprog

I want to know if there is any way that I needed to include the line #include <corr.h> in my program and I only had to type:

gcc myprog.c -o myprog

in order to compile?
I apreciate if anyone could send me a link where I can find the info I need or if anyone can explain how do I do that.

Thanks for any help!
Fernando
  Reply With Quote
Old 03-13-2002, 10:43 PM   #2
Registered User
 
rohit's Avatar
 
Join Date: Feb 2002
Posts: 69
even when you have the library with you you can not do
gcc myprog.c -o myprog

to generate myprog binary you will have to link it with your library.


gcc -o myprog -L/usr/lib/yourlibrary -I/yourincludepath myprog.c



cheers
Rohit
rohit is offline   Reply With Quote
Old 03-22-2002, 08:43 PM   #3
Registered User
 
Join Date: Nov 2001
Posts: 6
make library such as stdio.h

I have the same question.
How do I made my own library, so I could use it like:

#include <stdio.h>
#include <mylib.h>

without specifying the library path (you don't have to specify
the path for 'stdio.h', do you)?
M-21 is offline   Reply With Quote
Old 03-27-2002, 01:14 AM   #4
Registered User
 
Join Date: Aug 2001
Location: computers/ theatre, travelingstudentL>- Northern California NativeNorthern California3D&Tie-DyeStudent1>. Admirer of C Bangalore Net surfingTeacher >/ >0 nagpurteaching >1  >2
Posts: 61
This is the syntax for IRIX 6.5. It should be similair for your version of linux.

To compile a library:
cc -shared corr.c -o libcorr.so

This will create a shared object. you will need to place the file in a directory specified in your LD_LIBRARY_PATH environment variable.

To compile the executable:
cc myprog.c -lcorr -o myprog

The option -lxxx links in objects from the libxxx.so or libxxx.a (in that order) from directories in the LD_LIBRARY_PATH

This is just like when you use math.h, you have to include the -lm option when you compile.
sigma is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming library with built in manager cyreon C Programming 5 06-26-2009 12:49 PM
What's an import library? chiefmonkey C++ Programming 1 06-19-2009 05:00 PM
standrad library sarahr202 C++ Programming 11 05-18-2009 08:50 PM
create a static library from C++ and C code lehe C++ Programming 1 04-06-2009 07:28 PM
Create a user library mabuhay C Programming 8 11-03-2005 03:42 PM


All times are GMT -6. The time now is 06:40 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22