November 20, 2010

blex blex
Lab Rat
192 posts

Linux. qmake. Libraries in the same directory as an application

 

Linux.

Suppose that libraries are located in the same directory as an application.
If we start the application then it fails with message that library not found.

The simplest way to solve this is to add “.” to $LD_LIBRARY_PATH.
The better approach is to specify linker flag -Wl,-rpath,’$$ORIGIN’ in Makefile (for LFLAGS).

The question: How to add the flag to Makefile using *.pro file? I cannot understand what characters should be escaped and how to do this.

Any advices?

 Signature 

————————————

Oleksiy Balabay

11 replies

November 20, 2010

brandont brandont
Lab Rat
18 posts

See documentation. [doc.qt.nokia.com]

November 20, 2010

Bradley Bradley
Lab Rat
314 posts

  1. unix:!mac{
  2.   QMAKE_LFLAGS += -Wl,--rpath=\\\$\$ORIGIN
  3.   QMAKE_LFLAGS += -Wl,--rpath=\\\$\$ORIGIN/lib
  4.   QMAKE_LFLAGS += -Wl,--rpath=\\\$\$ORIGIN/libs
  5.   QMAKE_RPATH=
  6. }

Setting the QMAKE_RPATH clears the default rpath setting for the Qt libraries. This allows for bundling the Qt libraries with the application. If you want the rpath to include the path to the Qt libraries, don’t set QMAKE_RPATH.

 Signature 

Nokia Certified Qt Specialist.

November 20, 2010

blex blex
Lab Rat
192 posts
brandont wrote:
See documentation. [doc.qt.nokia.com]

Thank you for link, but I already read that section. I will try to clarify my question.

If I add to *.pro file the string

  1. linux-g++-64:LIBS+=-Wl,-rpath,’$$ORIGIN’

then I get in Makefile the flags:

  1. LIBS          = -Wl,-rpath,’’

instead of expected

  1. LIBS          = -Wl,-rpath,’$$ORIGIN’

So, the question: What I should add to *.pro file to get the expected string in Makefile

 Signature 

————————————

Oleksiy Balabay

November 20, 2010

blex blex
Lab Rat
192 posts
Bradley wrote:
Setting the QMAKE_RPATH clears the default rpath setting for the Qt libraries. This allows for bundling the Qt libraries with the application. If you want the rpath to include the path to the Qt libraries, don’t set QMAKE_RPATH.

Bradley, thank you! Exactly what I want, even more! Note about QMAKE_RPATH also very useful.

But I got the string in Makefile

  1. LIBS          = -Wl,-rpath,’$$ORIGIN’

with slightly different number of back slash characters:
  1. QMAKE_LFLAGS += -Wl,-rpath=\'\$\$ORIGIN\'

So, the problem is solved.

 Signature 

————————————

Oleksiy Balabay

December 4, 2010

blex blex
Lab Rat
192 posts

Problem still not solved.

I generate the *.pro file from the perl script. The command is the following:

  1. $cmd_line = "qmake -project -o $ARGV[0].pro ".
  2.  
  3.  
  4. << skipped >>
  5. " linux-g++-64:QMAKE_LFLAGS+=-Wl,-rpath=\'\$\$ORIGIN\' ";
  6.  
  7.  
  8. print $cmd_line;
  9.  
  10.  
  11.  
  12. if (system($cmd_line)) {
  13.  
  14.   die "Error generating pro-file $ARGV[0], stopped";
  15.  
  16. }

But I should escape characters in the perl script. Please advice how to do that, because I spent nearly one hour without any result. Escape sequense in perl, then is bash, then in qmake arguments processing… In the output file I should get the following:

  1. QMAKE_LFLAGS += -Wl,-rpath=\'\$\$ORIGIN\'

 Signature 

————————————

Oleksiy Balabay

December 4, 2010

Tobias Hunger Tobias Hunger
Robot Herder
3387 posts

Debian strongly argues against using rpath [wiki.debian.org]: It can blow into your face when you do not have all the dependencies under control.

So rpath is not “the better way”, it is just another way with different issues you need to consider.

December 4, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1654 posts

Tobias, so you are for creating script that will set LD_LIBRARY_PATH ? Or there is another way, diffrent from rpath and LD_LIBRARY_PATH? I’ve already used LD_LIBRARY_PATH way, but if there is something better it will be good new knowledge.

December 4, 2010

blex blex
Lab Rat
192 posts

Tobias Hunger wrote:
Debian strongly argues against using rpath [wiki.debian.org]: It can blow into your face when you do not have all the dependencies under control.

So rpath is not “the better way”, it is just another way with different issues you need to consider.

Thank you for link, very interesting. But, unfortunately, I should adopt to the existing development environment in our company. So, the question is still open.

 Signature 

————————————

Oleksiy Balabay

December 4, 2010

Bradley Bradley
Lab Rat
314 posts

Using LD_LIBRARY_PATH is equivalent to using rpath. The setting is in a script rather than in the executable, but the effect and the consequences are the same. Of course from the Linux distro point of view, neither LD_LIBRARY_PATH or rpath is good for library compatibility or security problems. However, from a developer of user software point of view, they are necessary for simplifying what is required for user installation.

 Signature 

Nokia Certified Qt Specialist.

December 4, 2010

Volker Volker
Ant Farmer
5428 posts
blex wrote:
Problem still not solved. I generate the *.pro file from the perl script. The command is the following:

Generating backslashes with perl is a PITA. In your case you additionally must triple qoute the string:

  1. quote for your perl script to generate the right string
  2. quote for the shell command you execute
  3. quote for the .pro file

I’d suggest you go the reverse order. Make it work in the .pro file, then construct the correct shell command line manually, then have the perl script spit out the command line.

December 5, 2010

xsacha xsacha
Lab Rat
517 posts

Bradley wrote:
Using LD_LIBRARY_PATH is equivalent to using rpath. The setting is in a script rather than in the executable, but the effect and the consequences are the same.

But LD_LIBRARY_PATH is much easier to change (for an end-user) if their paths have changed.

You can also use `ldd` to check where it is finding your libraries.

 Signature 

- Sacha

 
  ‹‹ Working with Excel Sheet?      light weight application In QT ››

You must log in to post a reply. Not a member yet? Register here!