【问题标题】:Preprocessor definition works in Visual Studio and doesn't work in Qt-creator预处理器定义在 Visual Studio 中有效,在 Qt-creator 中无效
【发布时间】:2012-10-28 10:59:02
【问题描述】:

.pro 文件:

DEFINES += MY_HEADER=\"test.h\"

cpp 文件:

#include MY_HEADER

在 Qt-Creator 中编译失败并出现错误:

错误 C2006:“#include”:需要一个文件名,但找到了“标识符”

编译器命令行似乎是正确的:

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\nmake.exe" -f Makefile.Debug cl -c -nologo -Zm200 -Zc:wchar_t- /E -Zi -MDd /E -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DMY_HEADER="test.h" -DLLL=3 -DQT_DLL -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"c:\Qt\4.7.4\include\QtCore" -I"c:\Qt\4.7.4\include" -I"c:\ Qt\4.7.4\include\ActiveQt" -I"debug" -I"..\testdefine" -I"." -I"c:\Qt\4.7.4\mkspecs\win32-msvc2010" -Fodebug\@C:\Users\Ekimov-A\AppData\Local\Temp\nm9C17.tmp

当使用 Qt-addin 将项目导入 Visual Studio 时,此代码编译时没有任何问题。

【问题讨论】:

  • 我尝试了 MY_HEADER=test.h 和 'MY_HEADER="test.h"',结果相同。
  • 对于第一个变体命令行包含 -DMY_HEADER=test.h,对于第二个 -DMY_HEADER="test.h"。
  • 如果我定义类似 DEFINES += LLL=3, int a = LLL;一切都很好。

标签: c++ visual-studio qt qmake c-preprocessor


【解决方案1】:

这似乎是一个 qmake 错误(功能?)。可能的解决方法:

DEFINES += 'MY_HEADER=\\\"test.h\\\"'

DEFINES += MY_HEADER=\\\"test.h\\\"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-25
    • 1970-01-01
    相关资源
    最近更新 更多