LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-10-2010, 02:05 PM   #1
suryaemlinux
Member
 
Registered: Mar 2009
Distribution: CentOS, Fedora
Posts: 34

Rep: Reputation: 0
Addition of a static library(libtimer.a) in Linux Makefile


Hi,
The following is my Makefile, I wanted to add a staic library named libtimer.a. I'm using the following Makefile. Please let me know how to add this static library:


Makefile:-
Quote:
all:
gcc -Wall -lrt -lm -pthread usbserialapp.c usbserialinit.c environ.c -o usbserial
It produces "usbserial" executable.


Thanks,
S
 
Old 02-10-2010, 02:53 PM   #2
jiobo
Member
 
Registered: Nov 2008
Posts: 180

Rep: Reputation: 36
If you are using GNU gcc, then they have documentation for gcc on their website. www.gnu.org

You can also take a look at the man pages:

Code:
man gcc
man make
There is also a manual for the make utility:

http://www.gnu.org/software/make/manual/

If you are using the ldd linker, then you would want to know about that as well:

Code:
man ldd
I think that you can try -l:libname.a which will use the libname.a file to link instead of the libname.so. Read up on the gcc command to use for it. I think that it is
Quote:
-Wl,-l:libname.a
 
Old 02-10-2010, 03:40 PM   #3
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Quote:
Originally Posted by suryaemlinux View Post
Hi,
The following is my Makefile, I wanted to add a staic library named libtimer.a.
So, just add it :-)

Code:
# gcc -Wall -lrt -lm -pthread usbserialapp.c usbserialinit.c environ.c libtimer.a -o usbserial
The -l:<lib_name> should work as well. If you get an error with -l: you have to add a -L <dir_to_lib> before specifying -l:

- Andi -
 
Old 02-11-2010, 12:29 PM   #4
suryaemlinux
Member
 
Registered: Mar 2009
Distribution: CentOS, Fedora
Posts: 34

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jiobo View Post
If you are using GNU gcc, then they have documentation for gcc on their website. www.gnu.org

You can also take a look at the man pages:

Code:
man gcc
man make
There is also a manual for the make utility:

http://www.gnu.org/software/make/manual/

If you are using the ldd linker, then you would want to know about that as well:

Code:
man ldd
I think that you can try -l:libname.a which will use the libname.a file to link instead of the libname.so. Read up on the gcc command to use for it. I think that it is

Thanks for your Info. For some reason -Wl,l:libname.a didn't work for mea earlier as well.
 
Old 02-11-2010, 12:30 PM   #5
suryaemlinux
Member
 
Registered: Mar 2009
Distribution: CentOS, Fedora
Posts: 34

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ForzaItalia2006 View Post
So, just add it :-)

Code:
# gcc -Wall -lrt -lm -pthread usbserialapp.c usbserialinit.c environ.c libtimer.a -o usbserial
The -l:<lib_name> should work as well. If you get an error with -l: you have to add a -L <dir_to_lib> before specifying -l:

- Andi -
Both worked man, thanks.
 
  


Reply



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
Is it Possible to create a static library in linux using C and Java langauges. raghuhrcta Linux - General 0 07-10-2009 05:44 AM
creating static library that includes another static library kskkumar Programming 2 10-22-2007 10:51 AM
Port Static Library from linux to windows? Dooshlibob Programming 1 03-12-2007 06:05 PM
LINUX - linking archive (static library) with shared (dynamic) library gurkama Programming 5 03-04-2007 11:11 PM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 04:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:34 PM.

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
Open Source Consulting | Domain Registration