Results 1 to 6 of 6

Thread: Can't run executable file directly: Cannot open shared object file

  1. #1
    Join Date
    Aug 2009
    Posts
    27
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Can't run executable file directly: Cannot open shared object file

    Hi all

    I built a library. Then another application to load that lib. I can build and run it using Qt Creator. But I can't execute the application in commandline (terminal). The error is: "Error while loading shared libraries: libtest.so.1: cannot open shared object file: no such file or directory.", despite that fact that I moved the library file to the directory of executable file (application).

    Please tell me how to get out of this "stupid" problem.

    Thanks a lot!

    Happy New Year of 2010, everybody!

    Cheers,

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can't run executable file directly: Cannot open shared object file

    Quote Originally Posted by rockballad View Post
    despite that fact that I moved the library file to the directory of executable file (application).
    This only works in Windows. On Unix the dynamic loader needs to be informed where the libraries are. If you don't want to place a library in one of the standard locations (like /usr/lib) you need to point the linker to the proper place. On Linux you would do it by setting the LD_LIBRARY_PATH environment variable to point to the directory containing your libraries. GCC can also hardcode a library search path by using the so called "rpath" linker directive.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2009
    Posts
    27
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't run executable file directly: Cannot open shared object file

    Thanks for your reply. That was I thought. Of course I did search a lot before posting the question here. But I also found that we should not use LD_LIBRARY_PATH (http://linuxmafia.com/faq/Admin/ld-lib-path.html). Now I'm trying to use LD_LIBRARY_PATH, as follows

    1/ Or I keep the old setting: LIB += libmylib.so
    2/ Or I specify LIBS += -L../mylibdir -lmylib -R../mylibdir

    with the mylibdir directory contains the libmylib.so file.
    I can build and run on Qt Creator. Outside, on Terminal, I "export LD_LIBRARY_PATH" before running, it's okay. At least it works.

    May I ask if we can specify the LD_LIBRARY_PATH on .pro file and after building successfully, we can run the executable file directly (No export action)?

    Thank you!
    Last edited by rockballad; 2nd January 2010 at 02:18.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can't run executable file directly: Cannot open shared object file

    Quote Originally Posted by rockballad View Post
    May I ask if we can specify the LD_LIBRARY_PATH on .pro file and after building successfully, we can run the executable file directly (No export action)?
    No, it's strictly a runtime setting. But you can use rpath, as already suggested.

    http://en.wikipedia.org/wiki/Rpath_%28linking%29
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    rockballad (2nd January 2010)

  6. #5
    Join Date
    Aug 2009
    Posts
    27
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't run executable file directly: Cannot open shared object file

    Quote Originally Posted by wysota View Post
    No, it's strictly a runtime setting. But you can use rpath, as already suggested.

    http://en.wikipedia.org/wiki/Rpath_%28linking%29
    Thank you, wysota!

  7. #6
    Join Date
    Jul 2008
    Location
    Philippines
    Posts
    60
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't run executable file directly: Cannot open shared object file

    You can also create a shell script like this:

    bash Code:
    1. #!bin/bash
    2. LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"path_of_your_libs"
    3. export LD_LIBRARY_PATH
    4. exec "./app_name"
    To copy to clipboard, switch view to plain text mode 

    Then make the script executable:

    bash Code:
    1. $chmod +x script_name
    To copy to clipboard, switch view to plain text mode 

    Hope this help! Cheers!
    Last edited by wysota; 15th June 2010 at 11:02.

Similar Threads

  1. KDE shared object file is missing
    By SimbadSubZero in forum Qt Programming
    Replies: 0
    Last Post: 13th December 2009, 15:43
  2. Related to Packaging of Qt4 Application
    By archanasubodh in forum Installation and Deployment
    Replies: 1
    Last Post: 21st March 2008, 15:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.