LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-20-2011, 04:19 AM   #1
manjunathgn1
LQ Newbie
 
Registered: Oct 2011
Posts: 3

Rep: Reputation: Disabled
Static library


Dear All,

How do we create and link static library (.a library and .so) from .c files

and use them in other .c files


WR
Manju
 
Old 10-20-2011, 01:05 PM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
In the directory where your C source files are (and they're only functions, no mains!), simply compile then to objects:
Code:
cc [options; e.g., -O2] -c *.c
Then create your library
Code:
for file in *.o
do
     ar rv libname.a ${file}
done
ranlib libname.a
That'll do 'er.

Oops, forget -- to link your programs with that library you
Code:
cc [options] -o prog prog.c -lname
Where name is the 'name' portion of libname.a; for example, the math library is named libm.a, you link it with -lm.

Hope this helps some.

Last edited by tronayne; 10-20-2011 at 01:07 PM.
 
1 members found this post helpful.
Old 10-20-2011, 01:49 PM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2017 CentOS6.9 CentOS7.3 + 50+ other Linux OS, for test only.
Posts: 16,742

Rep: Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318
And : libraries.so* are dynamic (or shared) libraries, not static.

http://tldp.org/HOWTO/Program-Librar...libraries.html
>> 3.4. Creating a Shared Library
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add a static library to my own static library gmsa Programming 6 03-31-2010 09:33 AM
creating static library that includes another static library kskkumar Programming 2 10-22-2007 11:51 AM
LINUX - linking archive (static library) with shared (dynamic) library gurkama Programming 5 03-05-2007 12:11 AM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 05:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration