Results 1 to 8 of 8

Thread: Shared libraries in Linux

  1. #1
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Question Shared libraries in Linux

    Hi,

    I have a question about shared libraries in Linux.

    When create my application in Windows, I can add the libraries I want to use simply in the .pro file:
    Qt Code:
    1. win32:release {
    2. LIBS += release/frist.dll \
    3. release/second.dll
    4. }
    5.  
    6. win32:debug {
    7. LIBS += debug/frist.dll \
    8. debug/second.dll
    9. }
    To copy to clipboard, switch view to plain text mode 

    The same code doesn't work in Linux:
    Qt Code:
    1. unix {
    2. LIBS += release/libfrist.so.1.0.0 \
    3. release/libsecond.so.1.0.0
    4. }
    To copy to clipboard, switch view to plain text mode 

    I'm able to compile the executable, but when I try to execute it, just nothing happens.
    I used ldd (terminal command) to list all libraries which are used by my executable. It lists my *.so-file, but it says "not found". The Qt libraries are also listed, but that can be found. Why isn't Linux able to find my libraries? I put them in the same directory as the executable. I also tried to put them to /usr/lib and to put them to /lib but that didn't work, too. Do I need to register the libraries first or did I do something wrong when I compiled the executable?

  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: Shared libraries in Linux

    It is "-L directorycontainingthelibrary -l nameofthelibrary" (both on Windows and Linux).
    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. The following user says thank you to wysota for this useful post:

    Infinity (21st October 2012)

  4. #3
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Shared libraries in Linux

    Thanks for the answer. The syntax works on Windows and I'll try it tomorrow on Linux.

  5. #4
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Shared libraries in Linux

    I'll tried to use the syntax like explained on Linux, but it does not work. On Windows it is working fine.

    Here's the code of my project file:
    Qt Code:
    1. unix {
    2. LIBS += -L../ -lIO \
    3. -L../ -lDialogs
    4. }
    To copy to clipboard, switch view to plain text mode 

    The compiler just says:
    cannot find -lIO
    cannot find -lDialogs
    collect2: Id returned 1 exit status
    What does the last line mean?

    The files libIO.so and libDialogs.so are stored in the same directory as the project file. This is also the path where the compiler stores the binary files (I tested it without using the libraries).
    It doesn't work if I remove the 'lib' before the libraries' filenames, too. When I compile the libraries, I also get some 'shortcuts' with version numbers of my *.so-file. Do I need them?

    I'm also wondering, why the compiler stored the binary files directly in the project folder. When I compile the same project on Windows, the compiler stored the binary files in the debug/release-folder (which is in the project folder). I'm not using a shadow build to specify the output directory (on Windows and Linux).
    Last edited by Infinity; 11th November 2012 at 18:27.

  6. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Shared libraries in Linux

    The compiler just says:
    Qt Code:
    1. cannot find -lIO
    2. cannot find -lDialogs
    3. collect2: Id returned 1 exit status
    To copy to clipboard, switch view to plain text mode 
    What does the last line mean?
    It means that ld (LD in lower case), your linker, failed. The two lines before it tell you why: neither IO nor Dialogs is the name of a library, or they cannot cannot be found in the standard library location or the additional (-L) paths you gave the linker. You should have files libIO.so and libDialogs.so for this to work as written. File names on Linux are case sensitive.

  7. #6
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Shared libraries in Linux

    Thanks for helping.

    I have the both library files (with the correct names, I mind the case sensitivity) in the directory where my project and the executables are stored. Maybe the problem is, that I'm using a relative path (-L../). I'll try to use an absolute path, when I'm working on Linux again. Makes it a difference, what kind of path I use on Linux (on Windows I noticed no difference)? And when I use a relative path, to what directory is it relative? I think it is the directory, where my Project-File is stored.

    I have an other question. The partition where the project files (of all my projects) are stored uses the NTFS file system. I'm not able to run my executables directly from that partition. Of course I tryed to set the entitlement of the executable to be able to run it, but that doesn't seem to work properly. If I copy the executable to an other partition with ext4 file system, I'm able to set the entitlement and to run the application. Is that a common problem (I found nothing on the Internet about it)? The distribution I'm using is LinuxMint.

    And there is still that question:
    When I compile the libraries, I also get some 'shortcuts' with version numbers of my *.so-file. Do I need them?
    Sorry for asking so many questions, I hope you can help me

  8. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Shared libraries in Linux

    You are using a relative path to the parent directory, the files are not there, and the default library search path rarely (if ever) includes the current directory.

    I doubt the NTFS partition preserves UNIX file permissions which are required to determine what is executable (rather than guessing based on file name like Windows).

    The "shortcuts" are symbolic links and are part of Linux/UNIX mechanisms to permit loading of libraries based on partial or no version numbers and simultaneous installation of different versions. The real file will typically be libblah.so.1.0.0 and the other links will be libblah.so, libblah.so.1, libblah.so.1.0, often forming a chain. You need at least the bare libblah.so during development or the "-lblah" option will not find the library. The other links are typically created automatically by the ldconfig program at install time.
    http://tldp.org/HOWTO/Program-Librar...libraries.html
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  9. The following user says thank you to ChrisW67 for this useful post:

    Infinity (13th November 2012)

  10. #8
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Shared libraries in Linux

    I finally solved the problem. The problem was just a missing permission (and not the relative path). There is the reading permission required but not the permission to execute. I guess the permission was missing, because the libraries were stored on a partition with NTFS file system (which doesn't support the UNIX permissions) and have just been copied to the ext4 partition.

    Thanks for your help.

Similar Threads

  1. Replies: 10
    Last Post: 20th December 2015, 11:14
  2. Replies: 4
    Last Post: 5th November 2011, 01:38
  3. QProcess on linux - problem with shared libraries
    By michallen in forum Qt Programming
    Replies: 1
    Last Post: 31st October 2010, 09:47
  4. Qt linguist and qt shared libraries
    By webquinty in forum Qt Tools
    Replies: 0
    Last Post: 15th July 2010, 09:44
  5. exception in shared libraries
    By big4mil in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2006, 19:51

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.