如何在#include指令中使用宏
How to use a macro in an #include directive?
我对如何在#include
指令中使用宏感到困惑。我已经这样做了:
#include "../../../../GlobalDefintions.h"
#include "../../../../lib/libc++/" ARCH_FAMILY_S "/" ARCH_S "/stkl/printkc/printkc.h"
GlobalDefintions.h :
#ifndef _GlobalDefintions_
#define _GlobalDefintions_
/*Architecture Information Start*/
#define ARCH i386
#define ARCH_FAMILY x86
#define ARCH_S "i386"
#define ARCH_FAMILY_S "x86"
/*Architecture Information End*/
#endif /*_GlobalDefintions_*/
但是它给我的是:
kernel.c++:24:88: fatal error: ./../../../lib/libc++/:没有这样的文件或目录# include "../../../../lib/libc++/" ARCH_FAMILY_S "/" ARCH_S "/stkl/printkc/printkc.h"之前是否有办法成功地将
ARCH_FAMILY_S
和ARCH_S
附加到我的#include
指令字符串?
您可以使用一系列宏来创建包含文件。不幸的是,我想不出任何更干净的(内部)方法来做到这一点。这适用于arm-eabi-none-gcc
v5.4.1。
#define LIBC_DIR ../../../../lib/libc++/
#define STRINGIFY_MACRO(x) STR(x)
#define STR(x) #x
#define EXPAND(x) x
#define CONCAT(n1, n2) STRINGIFY_MACRO(EXPAND(n1)EXPAND(n2))
#define CONCAT5(n1, n2, n3, n4, n5) STRINGIFY_MACRO(EXPAND(n1)EXPAND(n2)EXPAND(n3)EXPAND(n4)EXPAND(n5))
// Concatenate the five elements of your path.
// Of course, this can be simplified if there is only a prefix and a suffix
// that needs to be added and the ARCH_FAMILY, /, and ARCH are always present
// in the macro-generated #include directives.
#include CONCAT5(LIBC_DIR,ARCH_FAMILY,/,ARCH,/stkl/printkc/printkc.h)
相关文章:
- 每个 #include 指令的预处理器的时间成本是多少?
- "#include <path/to/header>"指令的含义(如"#include <loki/Functor.h>")
- 将#include指令包装到宏中
- #include 指令对SQL有意义吗?
- 在命名空间中放入一个标准的纯C头#include指令可以吗
- GDB不会停止与 #include 指令一致
- 来自 C 的指令 #include 和来自 C++ 的指令之间有什么区别吗?
- #include 指令中文件名的有效字符
- G++ 警告:#include 指令末尾的额外标记 [默认启用]
- 添加许多 -isystem include 指令是否会显著减慢编译过程
- C++中include指令和forward声明之间的区别
- 编写c++正则表达式以匹配#include预处理指令
- g++错误:预处理指令#INCLUDE无效
- 关于在C++中使用#include预处理器指令
- #include 指令和"using"语句的顺序在C++头文件的开头是否重要?
- 正确的#include指令格式
- 如何在#include指令中使用宏
- 在 extern "C" { ... } 中包装标准 C++ 标头的 #include 指令?
- 用宏构造#include指令的路径
- 为什么更常见的#include指令没有默认包含?