问题
I'm using a distributed compiler, and I need to add -m64
to CFLAGS
, CXXFLAGS
and LDFLAGS
. Usually, my definitions in .bashrc are fine, but qmake ignores them for some reason. The standard way of doing this seems to be to edit the .pro file, but I obviously don't want to hard-code the architecture. So, I can edit the .pro file, but I can't hard-code anything in it.
I tried setting CXXFLAGS like this:
QMAKE_CXXFLAGS += $(CFLAGS)
But it says:
Makefile:17: * Recursive variable `CXXFLAGS' references itself (eventually). Stop.
回答1:
I figured this out right before I posted the question, but since no one else has a good answer for this, I figured I'd post it anyway.
What I needed wasn't $(ENV_VAR)
, but $$(ENV_VAR)
, so I added these to my .pro
file:
QMAKE_CXXFLAGS += $$(CXXFLAGS)
QMAKE_CFLAGS += $$(CFLAGS)
QMAKE_LFLAGS += $$(LDFLAGS)
This makes qmake respect those environment variables. Note that qmake uses LFLAGS
instead of LDFLAGS
.
This is still not ideal, because you can need to re-run qmake
to change the environment variables, instead of having make
handle them intellegently, but it's definitely better than having to edit the .pro file every time.
来源:https://stackoverflow.com/questions/17578150/add-cflags-to-qmake-project-without-hard-coding-them-in-the-pro-file