首页 文章

如何在Qt中分离发布和调试版本?

提问于
浏览
4

我想将发布和调试版本的二进制文件放在源代码旁边的不同文件夹中 . 在.pro文件中:

CONFIG(debug){
    DESTDIR = ./debug
    OBJECTS_DIR = debug/.obj
    MOC_DIR = debug/.moc
    RCC_DIR = debug/.rcc
    UI_DIR = debug/.ui
}

CONFIG(release){
    DESTDIR = ./release
    OBJECTS_DIR = release/.obj
    MOC_DIR = release/.moc
    RCC_DIR = release/.rcc
    UI_DIR = release/.ui
}

对于发布版本,一切都很好 . 我在项目的根目录中有一个./release目录 . 但是对于调试版本,qmake没有't create a debug directory, it'的名字是 release (再次!):

qmake CONFIG+=debug CONFIG+=local 
// generates release and put everything in that directory
// but I want debug directory !

Update:

替换调试和释放的顺序,使调试目录 . qmake只能看到最后的配置...

2 回答

  • 5

    如果你真的需要进行源内构建并拥有单独的输出目录,我认为你需要根据documentation更改条件

    CONFIG(debug, debug|release){
        DESTDIR = ./debug
        OBJECTS_DIR = debug/.obj
        MOC_DIR = debug/.moc
        RCC_DIR = debug/.rcc
        UI_DIR = debug/.ui
    }
    
    CONFIG(release, debug|release){
        DESTDIR = ./release
        OBJECTS_DIR = release/.obj
        MOC_DIR = release/.moc
        RCC_DIR = release/.rcc
        UI_DIR = release/.ui
    }
    

    不过,不要问我为什么 . 恕我直言QMake是一个可憎的,应该不惜一切代价避免......

  • 3

    真正的解决方案是进行源外构建 . 这样,每次从调试到发布构建和返回时,都不必重新配置 . 这样做,使用以下内容:

    mkdir build-dbg
    cd build-dbg
    qmake ../foo.pro CONFIG+=debug
    cd ..
    mkdir build-rel
    cd build-rel
    qmake ../foo.pro CONFIG+=release
    

    作为额外的加分,您不会使用构建碎片污染源树 .

相关问题