1

I have a project file that starts like this:

VERSION = 0.9.9.0
DEFINES += VERSION_NUMBER=$${VERSION}

So I define a new constant VERSION_NUMBER that I can then access in the source code. However, later when I do:

qDebug() << VERSION_NUMBER;

The compilers tells me error: C2143: syntax error : missing ';' before 'constant' as if VERSION_NUMBER was not defined. Does anybody know what could be the reason?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
laurent
  • 88,262
  • 77
  • 290
  • 428

1 Answers1

2

You've got three issues to address here. First is that you need to put that VERSION_NUMBER=$${VERSION} assignment inside of quotes:

Add a define to qmake WITH a value?

The second is that it's not overly easy to get QMake to pass in a string literal #define. A lot of ways will just interpret your numbers-separated-by-periods as a poorly formed numeric constant:

http://robertcarlsen.net/2009/01/06/qmake-xcode-bug-258

This might get you somewhere with the issue...works on my setup, although it's a triple-escaped headache:

VERSION = \\\"'0.9.9.0'\\\"
DEFINES += "VERSION_NUMBER=$${VERSION}"

Third problem--probably the biggest--is that you're using QMake, which is outdated, and the Trolltech/Nokia people know it:

http://labs.qt.nokia.com/2009/10/12/to-make-or-not-to-make-qmake-and-beyond/

You should switch to something else (like CMake...which supports Qt and is used by KDE).

Community
  • 1
  • 1