Find the answer to your Linux question:
Results 1 to 3 of 3
Hello! Now that I've entered the realms of permanent beta software I'm completely lost. I compile a program like this: icc main.c -L. -lxyz -L/usr/X11R6/lib -lX11 -lpthread -lm -std=c99 (But ...
  1. #1
    Just Joined! WindowsDude's Avatar
    Join Date
    May 2010
    Location
    Wintopia
    Posts
    12

    "Cannot open shared object file"?

    Hello!

    Now that I've entered the realms of permanent beta software I'm completely lost.

    I compile a program like this:
    icc main.c -L. -lxyz -L/usr/X11R6/lib -lX11 -lpthread -lm -std=c99

    (But I have no concrete idea about what -L and -l mean. l is short for lib? Why? -L seems to specify the path for some library that follow directly afterwards?). Anyway, it works.

    So I get an output file a.out (why a?), which I run by writing ./a.out .

    Then I get this error message:
    error while loading shared libraries: lxyz.so: cannot open shared object file: No such file or directory

    I have it in my directory but it won't find it? What's wrong?

  2. #2
    Linux User
    Join Date
    Jan 2006
    Posts
    414
    -L is the path to search for libraries
    -l is the name of the library ( -lxyz would refer to libxyz.so)

    If a library is not in one of the standard library locations (/lib /usr/lib /usr/local/lib) then you need to tell ld - the dynamic linker - where it is when launching the program by using the LD_LIBRARY_PATH environment variable.

    This tells the linker where to look, and starts the program:
    Code:
    # LD_LIBRARY_PATH=/path/to/library ./program
    This is why a lot of games on *nix will actually be executed via a script, as you can set up any libraries the game may need while launching.

    This does the same thing as the comand above, but simplifies launching, the program could now be run with ./program.sh:
    Code:
    #!/bin/sh
    
    export LD_LIBRARY_PATH=/path/to/library
    
    /path/to/program
    As for a.out, this is because you didn't specify an output filename when compiling, just add
    Code:
    -o program
    to your compile command and instead of a.out, you program will be called program, or whatever you want to change it to.

  3. #3
    Just Joined! WindowsDude's Avatar
    Join Date
    May 2010
    Location
    Wintopia
    Posts
    12
    Thanks a lot, it works !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...