Visit the LQ Articles and Editorials section
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 04-18-2004, 03:56 PM   #1
Registered: Sep 2003
Distribution: Debian, Slackware
Posts: 39

Rep: Reputation: 15
static linking to c library

I'm a bit of a newcomer to linking. Does anybody know how to statically link to the c library and other user-defined libraries on linux? I use Mandrake, and I can't find the libc.a file on my system (nor am I sure what I would do with it). To dynamically link I run:

ld -shared <library object files> -o
ld -L . -dynamic-linker /lib/ \
-o testrun -lc -ltest <object files>

and this works just fine. But I'd like to do some benchmarking with staticly linked executables as well. Any help would be great ...

Old 04-19-2004, 09:58 AM   #2
Registered: Dec 2003
Location: Denmark
Distribution: Mandrake
Posts: 179

Rep: Reputation: 30
well you just type:
gcc -o foo bar.c -l[i]lib[/lib]

note: the -l is needed and it is not a capital i

note 2: you don't have to link to -lc this is done automaticly

happy hacking


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
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 05:20 AM
linking own library bobby2k3 Programming 2 10-20-2003 11:36 AM
Help Linking Library!! Please!! Musikolo Linux - Software 1 07-24-2003 04:16 PM
linking library simonissa Linux - Software 2 05-21-2003 10:41 AM
Static/dynamic linking ugenn Linux - Software 0 12-16-2002 12:01 AM

All times are GMT -5. The time now is 06:18 PM.

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