Add CFLAGS to QMake project without hard-coding them in the .pro file?

心已入冬 提交于 2019-12-23 16:33:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!