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?

2 Answers 2

118

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}
5
  • 10
    Not to forget $$(VAR) for Contents of an Environment variable at the time qnake (not Makefile!) is run
    – fawick
    Jun 8, 2012 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, 2014 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 8, 2014 at 2: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, 2015 at 16:51
  • ${} for build-in variables of QMake, such as ${QMAKE_FILE_NAME}.
    – user725757
    Nov 11 at 19:06
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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.