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 06-23-2004, 10:57 AM   #1
koodailar
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, 08:35 PM   #2
csfalcon
Member
 
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

Rep: Reputation: 31
try

Code:
gcc -L <path to library> test.o -l<library name>
 
Old 07-26-2004, 10:58 AM   #3
Sinner6
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, 03:35 PM   #4
psiakr3w
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 http://www.advancedlinuxprogramming.com/) 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 libname.so (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.
 
  


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

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

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