Results 1 to 2 of 2

Thread: linker cannot find shared library on Ubuntu

  1. #1
    Join Date
    Nov 2009
    Location
    Laval, France
    Posts
    124
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: linker cannot find shared library on Ubuntu

    Hi,
    I usually develop in Windows, so when trying to compile in Linux I feel like a total newbie.
    I have a link problem in a project, so to simplify my problem to the maximum, I created a console project with just a main.cpp
    which besides the user boilerplate code contains an include to ftrScanApi.h (a finger scanner's api header file)
    and a single call to the scanner initialisation routine ftrScanOpenDevice(); The file main.cpp links
    The problem is that there is a linker problem.
    The project file contains
    LIBS += -L/the/absolute/path/to/the/library -lScanAPI.so
    and the shared object library supplied is libScanAPI.so
    ls reports it's a file that takes 180K, so it does not seem to be a link to another file.

    and despite the simplicity of all of this I have the message
    cannot find -lScanAPI.so
    collect2: error: ld returned 1 exit status
    Now the file is obviously there, so what could go wrong?

    Hi,
    I usually develop in Windows, so when trying to compile in Linux I feel like a total newbie.
    I have a link problem in a project, so to simplify my problem to the maximum, I created a console project with just a main.cpp
    which besides the user boilerplate code contains an include to ftrScanApi.h (a finger scanner's api header file)
    and a single call to the scanner initialisation routine ftrScanOpenDevice(); The file main.cpp links
    The problem is that there is a linker problem.
    The project file contains
    LIBS += -L/the/absolute/path/to/the/library -lScanAPI.so
    and the shared object library supplied is libScanAPI.so
    ls reports it's a file that takes 180K, so it does not seem to be a link to another file.

    and despite the simplicity of all of this I have the message
    cannot find -lScanAPI.so
    collect2: error: ld returned 1 exit status
    Now the file is obviously there, so what could go wrong?


    Added after 1 38 minutes:


    If I type
    LIBS += /the/absolute/path/to/the/library/libScanAPI.so
    then the linker problem goes away.
    If I want a relative path, then I must take into account that the linker is being called inside a directory that may or may not be inside the sources, and I need to account for that...
    Last edited by feraudyh; 28th September 2017 at 20:03.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: linker cannot find shared library on Ubuntu

    Try it this way: -lScanAPI

    In linux, the "lib" prefix will be prepended to the front of the filename, and the appropriate ".lib", ".a", or ".so" will be appended. With your syntax, it is probably looking for libScanAPI.so.something, and of course can't find it.

    And I learned this the hard way: unlike in Windows, where you can specify libraries in any order to the linker, you must specify the libraries in linux in order of their dependencies. So if libA depends on libB, then you must tell the linker first about libA, then about libB. If you do it in the reverse order, then you'll get all kinds of unresolved dependencies from libA evn though you have also specified libB. The linker only drags in symbols it is -currently- looking for and then forgets about the library. If a library that comes afterward depends on the first library, too bad.

    For such a popular OS, linux toolchains seem quite stupid at times.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 1
    Last Post: 6th September 2016, 16:10
  2. MSVC linker can't find library
    By torin in forum Newbie
    Replies: 1
    Last Post: 20th June 2013, 23:37
  3. Replies: 6
    Last Post: 17th August 2012, 20:35
  4. Compilation/Linker issues on Ubuntu 8.10
    By floyd in forum Installation and Deployment
    Replies: 0
    Last Post: 18th November 2009, 06:11
  5. Issues building 4.3.2 x11 shared version on Ubuntu 7.10
    By rickbsgu in forum Installation and Deployment
    Replies: 6
    Last Post: 11th December 2007, 01:44

Tags for this Thread

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.