QtCreator/QMake + SUBDIRS Template
-
I'm trying to learn QMake. I have used QtCreator to create a simple GUI project which consists of an empty form and the main.cpp code to instantiate it. It works fine.
To learn about the subdirs template I decided to split the project up as follows:
@project/
--project.pro
--view/
----view.pro
----form.cpp
----form.h
----form.ui
--program/
----program.pro
----main.cpp@The intention here is to create independent libraries rather than just organizing the project into separate folders.
The contents of the .pro files are as follows:
project.pro:
@TEMPLATE = subdirs
SUBDIRS = view program
CONFIG += ordered
CONFIG += debug
CONFIG += qt@view.pro:
@TEMPLATE = lib
CONFIG += shared
FORMS += ./form.ui
HEADERS += ./form.h
SOURCES += ./form.cpp@program.pro:
@TEMPLATE = app
SOURCES += main.cpp
LIBS += -L../view -lview
TARGET = ../project@This configuration compiles (in QtCreator) but won't run because the 'libview.so' library is built in a /view subdirectory and the library can't be found. I know I could probably modify the path used to locate shared libraries but I don't want to to do that yet.
So, in an attempt to build everything in the same directory, I have tried adding a TARGET variable to view.pro which sets the target to the same directory as the application:
@TARGET = ../view@
However, when I do this, although the 'libview.so' library is built in the correct directory, the build then fails with this message:bq. error: cannot find -lview
I don't understand why changing the TARGET (in view.pro) affects the LIBS (in program.pro).
I think I must be going about this the wrong way but I can't figure out what I'm doing wrong.
Any help would be appreciated.
-
As you talk of libview.so, I assume you're on Linux.
The current dir (".") is not part of the library search path. So the shared library loader cannot find the lib, even if it is in the same directory as the application executable.
You can solve this by setting the environment variable
@
LD_LIBRARY_PATH=.
@But it is strongly advised to not do this. See the "comment of Tobias Hunger":http://developer.qt.nokia.com/forums/viewreply/19695/ in another thread for an explanation.
You can omit the TARGET setting and set
@
LD_LIBRARY_PATH=../view
@You can set the variable in Creator, Project view, tab run settings, environment settings are on the bottom.