Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. QtCreator/QMake + SUBDIRS Template
Forum Updated to NodeBB v4.3 + New Features

QtCreator/QMake + SUBDIRS Template

Scheduled Pinned Locked Moved Qt Creator and other tools
3 Posts 2 Posters 7.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    demonGeek
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • D Offline
        D Offline
        demonGeek
        wrote on last edited by
        #3

        Thanks Volker, I did what you suggested and the application now runs properly.

        I didn't realize that the current directory would not be searched when looking for libraries, that's good to know.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved