Thread: what to pass GNU ld

  1. #1
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300

    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?
    Last edited by MK27; 10-27-2008 at 10:20 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #2

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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`
    Last edited by MK27; 10-27-2008 at 10:17 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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).
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Speed test result
    By audinue in forum C Programming
    Replies: 4
    Last Post: 07-07-2008, 05:18 AM
  2. Replies: 3
    Last Post: 11-22-2007, 12:58 AM
  3. Undefined symbols from ld? ; making bundle; gcc 3.3
    By profxtjb in forum C Programming
    Replies: 5
    Last Post: 06-15-2004, 01:31 AM
  4. ld: linking
    By ilear_01 in forum C++ Programming
    Replies: 0
    Last Post: 06-10-2003, 05:40 AM
  5. pass be reference versus pass by value
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 08-01-2002, 01:03 PM

Tags for this Thread