Latest LQ Deal: Latest LQ Deals
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 06-23-2004, 11:57 AM   #1
LQ Newbie
Registered: Jun 2004
Posts: 3

Rep: Reputation: 0
how to static link a specific library?

i am now practicing programming in c. i've compiled a shared library myself and successfully load it in another program. the problem is when i try to static link the shared library, say, using gcc -static, the libc is in the name list, which was not allowed by gcc. somebody told me that using -nostdlib could avoid the libc shared library, and i want to know if there exist any method that can static link a specific shared library, instead of link all.
Old 06-23-2004, 09:35 PM   #2
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

Rep: Reputation: 31

gcc -L <path to library> test.o -l<library name>
Old 07-26-2004, 11:58 AM   #3
LQ Newbie
Registered: Mar 2004
Distribution: United Linux(they forced me to)
Posts: 16

Rep: Reputation: 0
Would this work?

-Xlinker -Bstatic -lthelib -Xlinker -Bdynamic
Old 07-26-2004, 04:35 PM   #4
LQ Newbie
Registered: Jul 2004
Posts: 27

Rep: Reputation: 15
I was actually just reading chapter 2.3 (sections 2.3.1 and 2.3.2) of "Advanced Linux Programming" (check downloads at and I think it might be helpful for you.

The way I've interpreted your problem and the book (I'm not perfectly clear on your problem):
I don't think you can link a shared library statically. What happens is that sometimes there will be two versions of a library, one static and one shared/dynamic, named libname.a (a for archive) and (so for shared object). When you compile a program, the linker chooses the shared library (with the so extension) by default, and goes with the static version only if you specify -static on the command line when you compile/link. So I guess you'd need to make a static library as well in order for the -static option to work correctly.


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
shared to static library ofada Programming 2 07-08-2009 12:54 PM
static qt library in debian dun_noe Debian 2 05-23-2005 03:42 AM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 05:20 AM
static linking to c library lantern Programming 1 04-19-2004 09:58 AM
How to use own static library? chuanyung Programming 4 03-10-2004 08:54 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:53 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
Open Source Consulting | Domain Registration