GNU 如何理解是否设置了一个标志
How does GNU make understand if a flag is set?
我正在处理一个带有makefile的C++项目。我必须对它进行一些修改,但在此之前,我有一个关于 GNU 中解释标志的方式的问题。为了详细说明,在下面的代码片段中,我有两个选项可以在编译项目期间启用或禁用功能,
# 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
现在在编译过程中,当我说使 FEATURE = on 时,我看到程序工作正常,启用了该功能。当我说使功能=关闭时,它被禁用。
然而,我的问题是我不完全理解编译器如何解释我的选择。例如,我只是说,"make FEATURE = off",这一行如何映射到启用 off 标志的事实,以及如何在关闭该功能的情况下编译代码?正如我上面所写的,我确实将我的功能的标志添加到 CXXFLAGS 中,但是如何理解 FEATURE = off 意味着设置了 FEATURE_DISABLED 标志?
非常感谢您的任何解释。
因为你写了
CXXFLAGS += $(CXXFLAGS_$(FEATURE))
当您在make
命令行上提供FEATURE = off
时,它将扩展到
CXXFLAGS += $(CXXFLAGS_off)
其中,因为您还定义了
CXXFLAGS_off = -DFEATURE_DISABLED
反过来扩展到
CXXFLAGS += -DFEATURE_DISABLED
这意味着编译器将使用-DFEATURE_DISABLED
作为额外的参数运行。
相关文章:
- cmake在构建过程中使用另一个工具检测标志
- 如何防止另一个线程修改状态标志?
- Python:我们应该如何编写一个函数来返回对象/列表和布尔标志
- Dlib:如何初始化一个忽略标志设置为1的mmodrect
- 在C 中创建一个巨大的标志地图
- 扩展一个简单的makefile以支持不同的隐式编译器标志
- 我如何在Qurl中包括一个百分点的标志
- 为什么当一个流被打开时,它被截断了 ios::ate 和 ios::out 标志
- CreateProcess( ) 不会创建一个带有CREATE_NEW_CONSOLE标志的新窗口 - C/C++
- 为什么C++11编译器支持仍然需要一个标志
- 在C++中,如何在一个参数中测试多个标志之一和"|"?
- 使用 "-g" 标志进行生产是否是一个好主意?
- 为Qt项目创建一个标志或使用QLoggingCategory
- 从Makefile中的C++FLAGS中删除一个标志
- 我应该使用什么标志来强制执行一个好的C++11样式
- gzgetc在读取最后一个字符时设置EOF标志
- 如何告诉编译器使用c++ 2011 _in_code_而不是一个标志
- 为一个c++ vector成员添加一个标志
- 如何正确设置一个标志
- GNU 如何理解是否设置了一个标志