BuvinJ
BuvinJ

Reputation: 11048

How to pass a QMAKE variable from the command line?

I am to trying cross-compile pile Qt from a Linux terminal. When I run qmake it applies the mkspecs qmake.conf in my context in such manner that the CROSS_COMPILE variable must be defined. For example, there is a critical conf line that looks like this:

QMAKE_CXX               = $${CROSS_COMPILE}g++

Qmake returns an error though which clearly indicates $${CROSS_COMPILE} is not being resolved. It is simply using "g++" instead of the whole value which ought to be there.

I've tried to invoke qmake and define the variable from a bash script like this:

qmake qt.pro "CROSS_COMPILE=${CROSS_COMPILE}"

And like this :

qmake qt.pro -- "CROSS_COMPILE=${CROSS_COMPILE}"

And a few other such stabs at it. I've also tried hard coding the value in that command in case that had anything to do with it. I've tried defining this as an environmental variable too (just in case)...

Nothing works. Yet, I've seen piles of examples where this syntax seems to be valid. What am doing wrong? Could there be a character escape complication?

Upvotes: 1

Views: 3033

Answers (2)

Larry
Larry

Reputation: 462

Your problem is that the shell already interpreted the ${} inside your string as a form of variable substitution. Since you did not define the variable CROSS_COMPILE in the shell, it had no value and what qmake got were actually the 2 arguments between quotes "qt.pro" and "CROSS_COMPILE=", meaning that you have actually made qmake set CROSS_COMPILE to an empty value. What you should try is:

qmake qt.pro "CROSS_COMPILE=\${CROSS_COMPILE}"

Note the backslash before the dollar sign, which escapes it to prevent it from having a special meaning to the shell and enables it to get passed on literally to qmake.

This question has also been already asked on Stackoverflow:

Define a string in qmake command line

More on the variable substitution of Bash:

https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html

EDIT:

Example: I just tried myself with a fresh project file with the following contents:

SOME_OTHER_VAR=$${SOME_VAR}_something
message($${SOME_OTHER_VAR})

and doing

SOME_VAR=value
qmake qmake_variables.pro "SOME_VAR=${SOME_VAR}"

does work for me, printing:

Project MESSAGE: value_something

Upvotes: 1

BuvinJ
BuvinJ

Reputation: 11048

This is not the best answer, but I "solved" the problem by adding this to my qmake.conf:

CROSS_COMPILE=$$(CROSS_COMPILE)

That defined the variable in qmake by getting it from an environmental variable I set in my calling bash script.

Upvotes: 0

Related Questions