60

I have a qmake file generated by Qt creator. I am modifying it but I do not manage to understand how to create a variable.

For example, I want to declare the library MYPATH as I did here:

MYPATH = /lib/aaa/bbb
unix:!macx:!symbian: LIBS += -L$(MYPATH)

When I run qmake I find in the generated makefile

LIBS = ....... -L$(MYPATH) .....

But the MYPATH variable is not declared anywhere.

Does anyone know how to declare such a variable properly?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Cristas
  • 720
  • 2
  • 8
  • 11

2 Answers2

117

QMake uses its own syntax for variable references.

  • VAR = foobar => Assign value to variable when qmake is run
  • $$VAR => QMake variable's value at the time qmake is run
  • $${VAR} => QMake variable's value at the time qmake is run (identical but enclosed to separate from surrounding text)
  • $(VAR) => Contents of an Environment variable at the time Makefile (not qmake) is run
  • $$(VAR) =>Contents of an Environment variable at the time qmake (not Makefile) is run

Try it like this

MYPATH = /lib/aaa/bbb
unix:!macx:!symbian: LIBS += -L$${MYPATH}
Phlucious
  • 3,704
  • 28
  • 61
jwernerny
  • 6,978
  • 2
  • 31
  • 32
  • 9
    Not to forget $$(VAR) for Contents of an Environment variable at the time qnake (not Makefile!) is run – fawick Jun 08 '12 at 12:03
  • 2
    So, what is the subtle difference between `$$VAR` and `$${§VAR}`? I've staring at each explanation and can't find a single difference... o.0 – Adri C.S. Sep 22 '14 at 11:15
  • 8
    @AdriC.S. I believe they are exactly the same. `$${VAR}` exists to resolve cases like `lib$$VERSION.dll`. without putting it between curly braces `lib$${VERSION}.dll`, the variable will not resolve because it is not followed by a space or a slash. – Zaw Lin Oct 08 '14 at 02:04
  • If would be nice if you add what does it actually mean 'at time of qmake' and 'at time of makefile'. I don't know myself, I thought we work with qmake and never worry about makefile. – zar Dec 16 '15 at 16:51
17

Other useful variable type: $$[...] This means "configuration option that were set when Qt was built"

Example:

message($$[QT_INSTALL_BINS])

This gives:

C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\bin
bocs
  • 171
  • 1
  • 2