![]() |
| | #1 |
| Guest
Posts: n/a
| How to create a library 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 |
|
| | #2 |
| Registered User 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 | |
| | #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 | |
| | #4 |
| Registered User Join Date: Aug 2001 Location: computers/ theatre, travelingstudent L >-
Northern California NativeNorthern California3D&Tie-DyeStudent 1>.
Admirer of C BangaloreNet surfingTeacher
>/
>0
nagpur teaching
>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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |