PDA

View Full Version : Shared library symbols won't be found unless I use QTLibrary



emitrax
15th May 2009, 15:51
Hi,

I'm using QTCreator (first time) to build a project that links to a shared library.

I've added (hopefully) the correct macros to the .pro file


INCLUDEPATH += /path/to/include/
LIBS += -L/path/to/lib -lmylib


but linking fails due to "undefined reference to" error.
I managed to solve the problem by using QTLibrary as explained at the
following link
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qlibrary.html#details
with the following example.


QLibrary myLib("mylib");
typedef void (*MyPrototype)();
MyPrototype myFunction = (MyPrototype) myLib.resolve("mysymbol");
if (myFunction)
myFunction();


Now I'd like to understand what I'm doing wrong because I'm sure can't resolve all library symbols that way.

Thanks in advance.

wysota
15th May 2009, 22:21
I've added (hopefully) the correct macros to the .pro file
They are not macros, they are variables.


but linking fails due to "undefined reference to" error.
What is the exact filename of the library and where is it placed? Also what is the symbol the compiler complains about?

emitrax
17th May 2009, 21:43
The library is place under my ~/lib and the path is added to ld.config. It is called libABC.so and it QTCreator does not see any symbol.

Is there any particular linker or compilar default flags that could be blamed for this ?

PaceyIV
20th May 2009, 09:52
I create my first personal library with qtcreator. It's a class that I compile with the template lib in the project.

I can use it without change anything in the ld.config.
I set the variable LIBS in this way:
unix:LIBS += -L/home/paceyiv/workspace/libs -lmyserialport
where my library is called libmyserialport.so.1.1.0. (When I compile it create also some symbolic links: libmyserialport.so, libmyserialport.so.1 and libmyserialport.so.1.1)

Try to compile with the full path.

Exists a way to run my program in Linux without copy my library to /usr/lib ?

PaceyIV
20th May 2009, 10:20
To my question, the answer is app.addLibraryPath(const QString &AbsolutePath);