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 07-01-2005, 04:21 PM   #1
Ikebo
Member
 
Registered: Jun 2004
Location: Michigan, USA
Distribution: Ubuntu
Posts: 77

Rep: Reputation: 15
minimal shared libaraies


Can anyone explain why ldd reports dependencies on certain shared libraries even though I make the attempt to link them into the binary?

The binary is noticeably bigger, ~500k as opposed to ~7k, but it seems there is no difference in the shared library dependencies.

Code:
[ike:~/temp]$ cat main.c
int main(void)
{
   return 0;
}
[ike:~/temp]$ gcc -o main main.c
[ike:~/temp]$ ls -l
total 12
-rwxr-xr-x  1 ike users 7348 Jul  1 17:12 main
-rw-r--r--  1 ike users   33 Jul  1 17:12 main.c
[ike:~/temp]$ ldd main
        linux-gate.so.1 =>  (0xffffe000)
        libc.so.6 => /lib/libc.so.6 (0x4101d000)
        /lib/ld-linux.so.2 (0x41004000)
[ike:~/temp]$ gcc -o main main.c `locate libc.a` `locate libc.so.6` `locate ld-linux.so.2`
[ike:~/temp]$ ls -l
total 513
-rwxr-xr-x  1 ike users 518706 Jul  1 17:12 main
-rw-r--r--  1 ike users     33 Jul  1 17:12 main.c
[ike:~/temp]$ ldd main
        linux-gate.so.1 =>  (0xffffe000)
        libc.so.6 => /lib/libc.so.6 (0x4101d000)
        /lib/ld-linux.so.2 (0x41004000)
 
Old 07-01-2005, 04:45 PM   #2
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
Uh,

But aren't you linking in the non-shared object version of libc in the larger executable? You seem to be resolving the libc dependencies with the .a, not the .so version of the library in your second compilation.
 
Old 07-01-2005, 10:43 PM   #3
sind
Member
 
Registered: Jun 2005
Posts: 75

Rep: Reputation: 15
This should do what you're after:

$ gcc -static -o main main.c

EDIT: Actually, that's probably not what you were after... Linking statically against libc without specifying -static might need a bit more work as there is an implicit -lc on the linker's command line - see:

$ gcc -v -o main main.c

EDIT: I ran nm on the compiled executable, after running:

$ gcc -o main main.c /usr/lib/libc.a

And there is one reference to the shared glibc:

w pthread_setcancelstate@@GLIBC_2.0

Don't know if I've helped at all or just babbled...

~sind

Last edited by sind; 07-01-2005 at 11:10 PM.
 
Old 07-01-2005, 11:17 PM   #4
Ikebo
Member
 
Registered: Jun 2004
Location: Michigan, USA
Distribution: Ubuntu
Posts: 77

Original Poster
Rep: Reputation: 15
I don't think the question was clear from the start, but you have answered it. Thanks for the reply.
 
  


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
error while loading shared libraries: libstdc++.so.5: cannot open shared object file: Franziss Linux - Newbie 10 06-28-2010 05:47 AM
Urgent !!! rpm: error while loading shared libraries: libelf.so.1: cannot open shared tinaa Linux - Software 5 12-02-2008 03:19 PM
error while loading shared libraries: libdb-4.1.so: cannot open shared object file putquery8581 Linux - Software 1 10-01-2004 07:03 AM
mplayer: error while loading shared libraries: libdvdread.so.3: cannot open shared ob Bruce Hill Slackware 6 12-11-2003 08:34 AM
linux init error in loading shared shared libraries akaran Linux - Software 1 05-28-2003 04:40 AM

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

All times are GMT -5. The time now is 09:43 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