【发布时间】:2014-03-31 07:53:51
【问题描述】:
我正在开发一个带有 makefile 的 C++ 项目。我必须对其进行一些修改,但在此之前,我有一个关于标志在 GNU make 中的解释方式的问题。详细来说,在下面的 sn-p 中,我有两个选项可以在我的项目编译期间启用或禁用某个功能,
# Two options for a feature:
FEATURE=on off
# other lines in the make file
# By default, the feature is turned off
ifndef FEATURE
FEATURE = off
endif
# other lines in the make file
# A number of other flags are defined here
# I have defined a flag to indicate that my feature is disabled
CXXFLAGS_off = -DFEATURE_DISABLED
# Adding all the flags
CXXFLAGS += $(CXXFLAGS_$(FEATURE)) #Other flags also added
现在,在我的代码中,我有这行:
#ifdef FEATURE_DISABLED
//Don't invoke the functions for the feature
#else
//Invoke the functions for the feature
#endif
现在在编译期间,当我说 make FEATURE = on 时,我看到程序运行良好,并且启用了该功能。当我说 make FEATURE = off 时,它被禁用了。
然而,我的问题是我并不完全理解编译器是如何解释我的选择的。例如,我只是说,“make FEATURE = off”,这一行是如何映射到启用关闭标志的事实以及在关闭该功能的情况下如何编译代码的?正如我上面所写,我确实将我的功能的标志添加到 CXXFLAGS,但是如何理解 FEATURE = off 意味着设置了 FEATURE_DISABLED 标志?
非常感谢您的任何解释。
【问题讨论】:
标签: c++ makefile compiler-flags