【问题标题】:How to specify separate compilation options for different targets in qmake?如何在 qmake 中为不同的目标指定单独的编译选项?
【发布时间】:2013-01-30 12:40:01
【问题描述】:

有没有办法在 qmake 中为不同的目标指定单独的编译选项?

例如:

QMAKE_CXXFLAGS += -O 
SOURCES += file1.cpp    

QMAKE_CXXFLAGS += -std=gnu++0x -O 
SOURCES += file2.cpp

因此 file1.cpp 将仅使用 -O 选项编译,文件 file2.cpp 使用 -std=gnu++0x -O 选项编译。

【问题讨论】:

    标签: qmake


    【解决方案1】:

    您可以创建和使用单独的“额外编译器”,如下所示:

    # Use the built-in compiler for file1.cpp
    QMAKE_CXXFLAGS += -O 
    SOURCES += file1.cpp    
    
    # Create a new compiler for file2.cpp
    gnupp0x.input = SOURCES_GNUPP0X
    gnupp0x.output = ${QMAKE_FILE_BASE}.o
    gnupp0x.commands = g++ -std=gnu++0x $$QMAKE_CXXFLAGS ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}
    QMAKE_EXTRA_COMPILERS += gnupp0x
    
    # Use the new compiler for file2.cpp
    SOURCES_GNUPP0X += file2.cpp
    

    【讨论】:

    • 我试过这个并且得到很多链接器错误。将-c 添加到gnupp0x.commands 行解决了这个问题。
    猜你喜欢
    • 2017-08-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    • 2020-04-10
    • 1970-01-01
    相关资源
    最近更新 更多