Results 1 to 7 of 7

Thread: Custom library problem

  1. #1
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Custom library problem

    Hello,

    first of all, my aplogies for posting this again. I've researched the forum and I've found plenty of old posts similar to this one. The thing is, all of them were solved by modifying the .pro file, which has not worked for me (I think my pro file is ok). Instead of resurrecting a dead post I created a new one.

    The problem is the inclusion of a library I made myself, called libCCCI.so into Qt4. I use eclipse Helios on a Ubuntu 10.04. The library libCCCI.so is in a folder called libs within my eclipse project.

    My .pro file looks like this:
    TEMPLATE = app
    TARGET = EPSI
    QT += core gui
    HEADERS += epsi.h
    SOURCES += main.cpp \
    epsi.cpp
    FORMS += epsi.ui
    RESOURCES +=
    INCLUDEPATH += ./libs
    LIBS += -lCCCI

    (I proved all set of combinations in the LIBS parameter, -Lfull path -l library, -Lrelative path -l library etc, but only got replicated -l entries in the g++ line and no solution)

    The resultant g++ call is:
    g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -Ilibs -Idebug -I. -o debug/main.o main.cpp

    So the directory is included (-Ilibs) but for some reason Qt4 does not see it. I also copied the library to the root of the project since it is also included (-I.) to see if it saw it there. It did not.

    I also added the library in the project->properties->C/C++ project paths->Libraries
    And the "libs" path in project->properties->C/C++ include paths and symbols

    I run make clean, qmake, make and it gives the next errors:
    For the include of header files from the library: No such file or directory
    For the objects of the library: Does not name a type.

    If I run the project regardless of the errors, I get the following message:
    error while loading shared libraries: libCCCI.so: cannot open shared object file: no such file or directory
    This is what makes me angry. It knows it is there. Somewhere. But it does not see it.

    Thanks to anyone who even bother reading this. I've already lost 4 days of work with this issue and I'm starting to get desperate (and so is my boss). If anyone could at least tell me if there is a problem with my pro file, that would be great.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Custom library problem

    For the include of header files from the library: No such file or directory
    Where is this header located ? In the "libs" directory ?
    If you want to use shared library in C app, you'll need header as well, not only .so file.

    Try to:
    0) fix the include .h error, this one has nothing to do with the fact that you are using .so file
    1) modify LD_LIBRARY_PATH to contain directory with .so library
    2) if it fails try to load it dynamically ( with dlopen("/path/to/lib.so") ) and eventually check error ( dlerror() )

    -----
    edit:
    now I saw this
    INCLUDEPATH += ./libs
    is this just a typo in your post ? or you have this line in .pro file ?
    Did you mean
    INCLUDEPATH += . libs
    ?
    Last edited by stampede; 2nd February 2011 at 17:58.

  3. #3
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Custom library problem

    God bless you with 10 fat pink children, stampede.

    I had indeed two problems, first the lack of the header files (I thought it was enough with the .so file, since the .h can be found within it, I was wrong). I copied them into the libs folder and that solved the linking and compilation problems.

    There was still the running time problem. It still said the library could not be found. That was solved by modifying the LD_LIBRARY_PATH variable.

    I have yet one more doubt. If that application is supposed to be portable, in every computer I'll have to export that variable manually first? Is there any way to do it through the eclipse Qt plugin so that whenever the program is called, the variable is automatically exported?


    Added after 12 minutes:


    Ok, from Eclipse that variable must be set within the Run configurations -> Environment.
    Setting the LD_LIBRARY_PATH in the project->properties->C/C++ Make Project->Environment did not work.

    Now I only need to find a way to export that variable from the compilation steps, so that from outside Eclipse the program can be executed without running the export LD_LIBRARY_PATH command. Until I find such a solution, I'll use this:

    #!/bin/bash
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./libs
    ./program
    Last edited by Dario; 3rd February 2011 at 09:22.

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Custom library problem

    Now I only need to find a way to export that variable from the compilation steps
    Have you considered using the "/usr/local" directory ? I think LD_LIBRARY_PATH should already contain "/usr/local/lib", so you can just put your .so file there without need to modify the path. The same applies to your library header ( "/usr/local/include" ).

  5. #5
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Custom library problem

    No luck.
    LD_LIBRARY_PATH is empty, so moving the library to /usr/local/lib is not helpful (the headers are not needed in execution time, so those are not required to be copied).

    Also I read an interesting article named "Why LD_LIBRARY_PATH is bad".
    http://xahlee.org/UnixResource_dir/_/ldpath.html
    Which motivates me to find a solution to this without using that variable.
    I'll try to find a solution to avoid using this variable. If I find it, I'll post it here. Also if anyone has a clue and can post it would be great.

  6. #6
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Custom library problem

    If you're building on Linux, qmake will use the 'RPATH' solution and eliminate the need for setting LD_LIBRARY_PATH; Google 'rpath' for more information.

    The problem seems to be your project file, which is a mess. You seem to be confusing the include path and the library path; the first is needed by the compiler, the second by the linker. No matter what solution you use, the linker still needs to know where to find the libraries your application needs so it can examine their symbol tables.

    Start by reading through the qmake documentation at http://doc.qt.nokia.com/latest/qmake-manual.html - all of it.

  7. The following user says thank you to SixDegrees for this useful post:

    sevenjay (16th February 2011)

  8. #7
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Custom library problem

    Quote Originally Posted by SixDegrees View Post
    If you're building on Linux, qmake will use the 'RPATH' solution and eliminate the need for setting LD_LIBRARY_PATH; Google 'rpath' for more information.
    Thank you.
    I do use "-L.. -l.." to indicate the library path like this:
    Qt Code:
    1. LIBS += -Lxxx/xxx/lib -lxxx
    To copy to clipboard, switch view to plain text mode 
    It was complied fine, but run error while loading shared libraries
    .
    According your suggestion, I add this:
    Qt Code:
    1. LIBS += -Wl,-rpath,xxx/xxx/lib
    To copy to clipboard, switch view to plain text mode 
    It runs fine.

Similar Threads

  1. Problem loading custom library in Qt4.5
    By ches in forum Newbie
    Replies: 2
    Last Post: 10th March 2009, 19:46
  2. custom widget library?
    By ihoss in forum Newbie
    Replies: 3
    Last Post: 16th September 2007, 16:39
  3. so shared library problem
    By mtrpoland in forum Newbie
    Replies: 3
    Last Post: 13th August 2007, 21:51
  4. Replies: 1
    Last Post: 5th March 2007, 20:50
  5. shared library problem
    By nhatkhang in forum KDE Forum
    Replies: 9
    Last Post: 28th November 2006, 04:07

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
  •  
Qt is a trademark of The Qt Company.