PDA

View Full Version : Running Application linking with shared libraries in Qt/Linux



payal
5th February 2010, 10:43
Hi .........

I have created a Qt application which uses some some shared libraries for running the executable.i am using Qt 4.4.0 on Windows XP.Now i want to port the same application on linux.

i am able to run a simple Qt app on linux using qmake -pro,den qmake and make..

i created the shared library(.so file) on linux using command
"gcc -shared -Wl,-soname,libctest.so.1 -o libctest.so.1.0 *.o" .

Now i want to link this library to an executable.Could you plz tel me how can i achieve it?i am getting undefined reference errors for Qt classes i have used while trying to link the library using gcc command.

Is there any way to accomplish these using qmake command.I am not using any IDE.

Plz provide some solution.


Thanks in advance......................

Regards,
Payal

nrabara
5th February 2010, 10:55
why not using qt creator ?

payal
5th February 2010, 10:58
k....i wil download it....

How it wil help in linking the shared libraries?could u plz explain on that?

jvdl
5th February 2010, 11:09
Read the following page http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html
This a very good tutorial about libraries on linux.

Note the following points that could go wrong:

Remember the -L option for the path to the library and the -l option for the lib itself while linking (of course you can also specify the complete path to the lib)
If you can create the binary, then it should be able to find the shared lib again. You can check this with the ldd command (very usefull!!). Just run "ldd <binary>".
If your binary can't find the library, you need to solve this with one of the 3 options mentioned on the page above under "Library Path"


Good luck!!

Joost

payal
5th February 2010, 11:30
Thanks alot..In that tutorial its mentioned how to link shared library with executable using command.......but the problem is i cant compile .cpp files developed in Qt using gcc/g++.

jvdl
5th February 2010, 12:38
In linux you use g++. Check the Makefile you created with qmake (variable CXX). In the Makefile there is also a LIBS variable which contains the libs it should use while linking. I noticed there that there is a SUBLIBS variable which is not set. I presume that if you simply do this on your command prompt:
export SUBLIBS='-L</path/to/your/shared/lib> -l<libname>'
And then you run make and you will be fine (I think).

Joost

faldzip
5th February 2010, 16:07
Your way seems to be overcomplicated... Is your shared library written in Qt? If so then in .pro file just set TEMPLATE=lib, run qmake and make without any "gcc -shared bla bla bla"
Did you ever try to look into pro file and check it's functionalities? Doing qmake -project is fine but only for creating basic .pro file - the base for your customization - it let you avoid boring typing to add all source files to SOURCES and headers to HEADERS but not more. And linking to any library is rather easy. In your application .pro file you add:


LIBS += -Lpath/to/your/library -lyourlibraryname

yourlibraryname is a filename without leading "lib" and trailing ".so*" so to link with "libmysql.so.4" you add "-lmysql". But then when you run your app your library has to be somewhere where OS can find it to link it dynamically so put it in your apps dir or in some dir listed in /etc/ld.so.conf or just add your library dir to /etc/ld.so.conf.

payal
8th February 2010, 05:56
Thanks alot, ur post is very helpful..........Now I am able to link the library.....

I have Done the steps whatever was mentioned in the last post..............have added the LIBS in the application .pro file and edited ld.so.conf and executed ldconfig command................

But when i am trying to run application,i am getting error like " error while loading shared libraries :libctest.so :cannot open shared object file :no such file or directory ....Dont have any idea ,how to solve the error? Could u plz help me in this regard?

Regards,
Payal

payal
8th February 2010, 07:03
yaa..........the error is solved by setting the LD_LIBRARY_PATH.:)

Cupidvogel
19th December 2015, 17:01
yaa..........the error is solved by setting the LD_LIBRARY_PATH.:)

How to set the LD_LIBRARY_PATH variable through Qt?

anda_skoa
20th December 2015, 11:14
How to set the LD_LIBRARY_PATH variable through Qt?

Since setting that variable would not have any effect on the application itself, I assume you are writing some for form of launcher application that runs programs via QProcess and needs to set their environment.

For that QProcess has QProcess::setProcessEnvironment().

Cheers,
_