Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8972625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:15:38+00:00 2026-06-15T18:15:38+00:00

I have a game with two separate projects for the application itself and the

  • 0

I have a game with two separate projects for the application itself and the tests. I’m building all of the projects in-source. Here’s a shortened version of my project structure:

game
    game.pro
    app
        app.pro
        Entity.h
        Entity.cpp
        Entity.o
        moc_Entity.cpp
        moc_Entity.o
    tests
        layer
            layer.pro
            Entity.o (duplicated)
            moc_Entity.cpp (duplicated)
            moc_Entity.o (duplicated)
            tst_Layer.cpp

app.pro:

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4) {
    QT += widgets
}

TARGET = cotw-clone
TEMPLATE = app

MOC_DIR = .moc
OBJECTS_DIR = .obj

HEADERS += MainWindow.h \
    Map.h \
    Tile.h \
    Character.h \
    Layer.h \
    NewGameDialog.h \
    GameController.h \
    Stair.h \
    Random.h \
    MapGenerator.h \
    TileData.h \
    Statistics.h \
    StatisticsDialog.h \
    StatisticWidget.h \
    Range.h \
    Level.h \
    RandomMapGenerator.h \
    AiController.h \
    MonsterJournalWidget.h \
    InventoryDialog.h \
    PathSearch.h \
    PathNode.h \
    Path.h \
    Geometry.h \
    EntityDatabase.h \
    EntityData.h \
    Entity.h \
    CharacterData.h \
    EntityMetadata.h

SOURCES +=\
    MainWindow.cpp \
    Map.cpp \
    Tile.cpp \
    Character.cpp \
    Layer.cpp \
    NewGameDialog.cpp \
    GameController.cpp \
    Stair.cpp \
    TileData.cpp \
    Statistics.cpp \
    StatisticsDialog.cpp \
    StatisticWidget.cpp \
    Level.cpp \
    RandomMapGenerator.cpp \
    AiController.cpp \
    MonsterJournalWidget.cpp \
    InventoryDialog.cpp \
    PathSearch.cpp \
    PathNode.cpp \
    Path.cpp \
    EntityDatabase.cpp \
    EntityData.cpp \
    Entity.cpp \
    CharacterData.cpp \
    main.cpp

FORMS += MainWindow.ui \
    NewGameDialog.ui \
    StatisticsDialog.ui \
    StatisticWidget.ui \
    MonsterJournalWidget.ui \
    InventoryDialog.ui

RESOURCES += \
    icons/icons.qrc \
    tiles/tiles.qrc

RESOURCES += \
    entities/entities.qrc

My problem is that all of the tests projects use classes from the app project, which means they’re compiling all of these classes even though they’ve already been compiled when app was built. Take the layer test project, for example:

layer.pro:

QT += testlib
QT -= gui

greaterThan(QT_MAJOR_VERSION, 4) {
    QT += widgets
}

TARGET = tst_LayerTest
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += tst_LayerTest.cpp
DEFINES += SRCDIR=\\\"$$PWD/\\\"

HEADERS += "../../app/Entity.h"
SOURCES += "../../app/Entity.cpp"

So how can I point qmake to the .o (and qrc_, .moc etc.) files that have already been produced in app? Is there some qmake variable for this purpose, or is my project structure just fundamentally flawed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:15:39+00:00Added an answer on June 15, 2026 at 6:15 pm

    You can use wildcards in qmake .pro files, to save having to maintain a list of all file names.

    For example,

    SOURCES += *.cpp
    

    Each time you run qmake, that pattern *.cpp gets expanded in to the current list of files matching the pattern.

    You can also use -= to remove file names, if you have a particular filename that you wish to exclude.

    For example:

    SOURCES += *.cpp
    SOURCES -= main.cpp
    

    Edit

    I almost suggested in my earlier answer that you introduce a library, using qt’s lib template, to contain your common code.

    Then your build structure would look like this – assuming that you can move files around, from app/ to lib/:

    game
        game.pro
        app
            app.pro
            main.cpp
        lib
            lib.pro
            Entity.h
            Entity.cpp
            Entity.o
            moc_Entity.cpp
            moc_Entity.o
        tests
            layer
                layer.pro
                tst_Layer.cpp
    

    You can find some info on library projects in “Building a Library” on the Qt website

    If, for some reason, you can’t move your files around, then you can introduce a new directory for the library, and have it pull in source files from the app directory – but that is definitely more faff, and more confusing:

    game
        game.pro
        app
            app.pro - builds only main.o
            main.cpp
            Entity.h
            Entity.cpp
            moc_Entity.cpp
        lib
            lib.pro
            Entity.o
            moc_Entity.o
        tests
            layer
                layer.pro
                tst_Layer.cpp
    

    Edit 2

    One problem you have is you are putting object files in to the LIBS variable, which defines what libraries your code will link against. So that’ll be why you are getting errors with those files.

    Try changing those LIBS uses to OBJECTS instead, and it may work.

    If not, have a read of this thread, which is asking pretty much the same thing.

    In particular, see the answer by ChrisW67 of ’13th May 2012, 10:14′ which begins;

    Try:

    OBJECTS += f1.o f2.o f3.o f3.o

    although I think that, if you have the source, building it into your
    app directly or via a library is a better option.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two separate apps on the market one a graphic game and another
I want (in my game) to have a mode where two people can be
I have two development sites call api.localhost and game.localhost . Both are running from
In a game application I have the following scenario: From the main game Activity
I have a game with two rootViewControllers - one for the Menu and the
I have two vectors defining two separate points in a three-dimensional space. One is
I currently have a GAME table with two fields user_id, win win = 1
I have built a two-player tic tac toe game in Java, using sockets (no
I'm building a simple game engine in javascript, and I'm currently building separate spritesheets
I have game and I have two threads , one generates custom class and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.