[Qt-creator] How *not* hard-code Qt Project Build Environment variable LD_LIBRARY_PATH ?
Ed Sutton
ESutton at fescorp.com
Tue Mar 30 18:17:26 CEST 2010
On Mar 30, 2010, at 10:36 AM, Ed Sutton wrote:
> Sorry, I am stuck on this...
>
> When it comes to dynamically loaded shared libs that are required at link time, I can not figure out the trick of completely removing hard-coded paths from my Qt Creator project build environment. Setting LD_LIBRARY_PATH under the Qt Project Build Environment to a relative path works fine for building / linking. Example:
>
> LD_LIBRARY_PATH=/opt/qtsdk-2010.02/lib/qtcreator:/home/esutton/projects/myproject/guiproject/../../lib
>
>
> Question: How can I replace the base part of the relative path with a variable?
>
> Replacing with $(PWD), does not work. Apparently at the build environment stage, PWD is set to the qmake working directory of "/opt/qtsdk-2010.02/qt/bin"
>
> LD_LIBRARY_PATH=/opt/qtsdk-2010.02/lib/qtcreator:$(PWD)/../../lib
>
>
>
> Can a variable added to the Qt project file be referenced in the Qt project Build Environment ?
>
> I tried adding this to my Qt Project File:
>
> MYLDLIBPATH = $$PWD/../../lib
> message(MYLDLIBPATH == $$MYLDLIBPATH)
>
> and adding a reference to this variable in the Qt project Build Environment:
>
> LD_LIBRARY_PATH=/opt/qtsdk-2010.02/lib/qtcreator:$(MYLDLIBPATH)
>
> This does *not* work even though the qmake message displays the desired path:
>
> Project MESSAGE: MYLDLIBPATH = /home/esutton/projects/myproject/guiproject/../../lib
>
> I am building under Red Hat Enterprise Linux 5.x. I do not want to use rpath because I want to avoid hard-coded paths in released binaries. My goal is to retrieve source code from the repository and to build a release using:
>
> qmake myproject.pro
> make
>
>
I found a solution myself for linking to shared libraries. Use rpath-link ( Just like the linker warning had informed me ;-)
If I understand it correctly, rpath-link, tells the linker where to look for run-time shared libs to link with and unlike rpath will not hard-code any run-time paths into my binaries.
LIBS += -L../../lib
#Note the character following the -Wl switch is a lower-case 'L'
LIBS += -Wl,-rpath-link,$$PWD/../../lib
LIBS += -lmysharedlib
-Ed
More information about the Qt-creator-old
mailing list