Reputation: 83
I'm trying to add a macro similar to #define CPP_COMPILER_SETTING "g++ -std=c++1z"
in the .pro
file:
DEFINES += "CPP_COMPILER_SETTING=\\\"g++ \\-std\\=c++1z\\\""
In the generated Makefile I get:
DEFINES = -DCPP_COMPILER_SETTING=\"g++ \-std\=c++1z\"
I'm getting this error upon compilation:
g++: error: \-std\=c++1z": No such file or directory
How should I escape the string so that it makes it from the .pro
file to the compiler's input?
Upvotes: 3
Views: 1563
Reputation: 98425
You need to have the following in the Makefile:
-DCPP_COMPILER_SETTING=\"g++\ -std=c++1z\"
^^ ^ ^^
To take it to a .pro
file, you need to escape backlashes and double quotes only. Thus, in the .pro
file, you'll have:
DEFINES += "CPP_COMPILER_SETTING=\\\"g++\\ -std=c++1z\\\""
Test case:
#include <iostream>
int main()
{
std::cout << CPP_COMPILER_SETTING << std::endl;
}
When you google qmake escaping defines with spaces, the first result is the correct solution.
Upvotes: 4