C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-27-2008, 09:05 AM   #1
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,944
what to pass GNU ld

So far, the only linker flags I've used have been as per some instructions...now, however, I'm trying to use libmpg123 (for which there are no online examples beyond their own API), and when I kept getting "undefined references" to functions that are exported by the included header (mpg123.h) I thought, why not try one of those -l thingies. So -lmpg123 got my test script past the compiler, but then when I run it:

./a.out: error while loading shared libraries: libmpg123.so.0: cannot open shared object file: No such file or directory

libmpg123.so.... is there, tho, so there must be some more different flags I need.
[edit: should have tried ldconfig!]

Given that I have the header and know where to find the libraries that I built from source, how can I determine (-lmpg123 was an easy guess) what flags I need to get everything to run?

Maybe there is some reading related to this somewhere?
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS

Last edited by MK27; 10-27-2008 at 10:20 AM.
MK27 is offline   Reply With Quote
Old 10-27-2008, 09:14 AM   #2
Registered User
 
C_ntua's Avatar
 
Join Date: Jun 2008
Posts: 1,134
See this:
http://www.network-theory.co.uk/docs...cintro_17.html
C_ntua is offline   Reply With Quote
Old 10-27-2008, 09:29 AM   #3
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,944
Quote:
Originally Posted by C_ntua View Post
This is useful to me, thanks...except it implies that there is no way to know except via educated guesses.

Anyone used _supported_decoders with mpg123 ? Or compiled anything with mpg123.h?

[later] so i forgot to call ldconfig after I "make install'd" mpg123 (isn't that usually done automatically?)
Anyway, for posterity, for at least some of the extended functions (the ones I tried so far), -lmpg123 is fine. But the proper flagset is in the examples makefile and it involves pkg-config:
gcc test.c `pkg-config --cflags --libs libmpg123`
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS

Last edited by MK27; 10-27-2008 at 10:17 AM.
MK27 is offline   Reply With Quote
Old 10-27-2008, 10:27 AM   #4
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,439
Quote:
except it implies that there is no way to know except via educated guesses.
True. Well, you can also read the build system's source to find out the names it generates.
__________________
All the buzzt!
CornedBee

"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
CornedBee is offline   Reply With Quote
Old 10-27-2008, 10:37 AM   #5
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
The link is happening fine. You are passing the right library name. The problem is that the linker search path is not the same as the loader search path, so ld.so is unable to find the library. You'll need to either move the library to some standard location or provide its explicit path in LD_LIBRARY_PATH
__________________
"Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot
brewbuck is offline   Reply With Quote
Old 10-27-2008, 11:09 AM   #6
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,944
Quote:
Originally Posted by brewbuck View Post
The link is happening fine. You are passing the right library name. The problem is that the linker search path is not the same as the loader search path, so ld.so is unable to find the library. You'll need to either move the library to some standard location or provide its explicit path in LD_LIBRARY_PATH
Yeah, exactly. Well, not exactly, because the library is in a standard path. But with my version of linux the loader uses a ld.so.cache file, which needs to be updated with ldconfig if you add new libraries into a standard path, or the loader won't find them (as if they weren't there).
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS
MK27 is offline   Reply With Quote
Reply

Tags
compiling, gcc, linker

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Speed test result audinue C Programming 4 07-07-2008 05:18 AM
Is this claim correct: "Anywhere you pass in a function, you can pass in a functor"? meili100 C++ Programming 3 11-22-2007 12:58 AM
Undefined symbols from ld? ; making bundle; gcc 3.3 profxtjb C Programming 5 06-15-2004 01:31 AM
ld: linking ilear_01 C++ Programming 0 06-10-2003 05:40 AM
pass be reference versus pass by value Unregistered C++ Programming 2 08-01-2002 01:03 PM


All times are GMT -6. The time now is 05:51 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22