DEFINES not visible in my project



  • I have a project that is composed of a main application and two personal libraries. I want to use some DEFINES in my project so I can put special code in when using this particular application. But I can't get my applicattion to "see" the defines. So this is the crux of the question.

    Let me briefly explain how the project fits together:

    The project has a main application and two of my own libraries. I am using a subdir file to "glue" it all together. The subdir .pro file has this:

    @QMAKE_CXXFLAGS_WARN_OFF -= -Wunused-parameter

    TEMPLATE = subdirs
    CONFIG += ordered
    DEFINES += IN_LOTUS_ENVIRONMENT

    QMAKE_CXXFLAGS_WARN_ON = ""
    QMAKE_CXXFLAGS_WARN_OFF += -Wunused-parameter

    SUBDIRS = ../Underworld ../EngineOGL ../Lotus@

    The application .pro file looks like this:

    @QT += core gui opengl widgets network

    TARGET = Lotus
    TEMPLATE = app
    CONFIG += c++11

    INCLUDEPATH = ..

    SOURCES += main.cpp
    mainwindow.cpp
    ...

    win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../Underworld/release/ -lUnderworld
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../Underworld/debug/ -lUnderworld
    else:unix: LIBS += -L$$OUT_PWD/../Underworld/ -lUnderworld

    INCLUDEPATH += $$PWD/../Underworld
    DEPENDPATH += $$PWD/../Underworld

    win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Underworld/release/libUnderworld.a
    else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Underworld/debug/libUnderworld.a
    else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Underworld/release/Underworld.lib
    else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Underworld/debug/Underworld.lib
    else:unix: PRE_TARGETDEPS += $$OUT_PWD/../Underworld/libUnderworld.a

    win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../EngineOGL/release/ -lEngineOGL
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../EngineOGL/debug/ -lEngineOGL
    else:unix: LIBS += -L$$OUT_PWD/../EngineOGL/ -lEngineOGL@

    You will notice in the subdir .pro file I defined a variable called: IN_LOTUS_ENVIRONMENT.

    But nothing responds to the DEFINE. Here's a typical example of what I need to do:

    @#ifdef IN_LOTUS_ENVIRONMENT
    uw::appinterface->informDisplayChanged();
    qDebug() << "Hi there!";
    #endif@

    This snippet of code, I am putting in one of the libraries. And it doesn't work. I'm sure its my ignorance using #define. I would appreciate any insights anyone has.


  • Lifetime Qt Champion

    Hi,

    You should either have them in a pri file that you include when needed or in a .qmake.conf file in the root of your project if you are using Qt 5

    Hope it helps



  • It might need to be inside each project file that uses it. Maybe a shared .PRI file with the define statement:

    shared.pri
    @
    DEFINES += IN_LOTUS_ENVIRONMENT
    // other 'common' items
    @

    application.pro (assuming shared.pri is one directory up)
    @
    include( ../shared.pri )

    TARGET = Lotus
    TEMPLATE = app
    CONFIG += c++11
    ...
    @

    and at the top of the project
    @
    QMAKE_CXXFLAGS_WARN_OFF -= -Wunused-parameter

    TEMPLATE = subdirs
    CONFIG += ordered
     
    QMAKE_CXXFLAGS_WARN_ON = ""
    QMAKE_CXXFLAGS_WARN_OFF += -Wunused-parameter
     
    SUBDIRS = ../Underworld ../EngineOGL ../Lotus
    

    @



  • This solves part of the problem. My application.pro file now includes:

    @include (shared.pri)@

    I can see the define IN_LOTUS_ENVIRONMENT in the main application. But my two libraries can't see it still.

    So if I go into my Underground library, the define isn't visible. I conceptually must not understand how DEFINES work. I figured if I put it in the top file, it would disseminate out to everything hanging off the project (which it does in the files directly associated with the application). But apparently, my libraries are independent entities unaware of the top file.

    The whole point of this is if my libraries are attached to a particular application, I wanted certain chunks of code to run. If I have to include the shared.pri file in the two libraries, it completely defeats the purpose of the DEFINE.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.