How to use a macro in an #include directive?(如何在#include 指令中使用宏?)
问题描述
我对如何在 #include
指令中使用宏感到困惑.我已经这样做了:
I'm confused on how to use macros in the #include
directive. I've done this:
#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++/: No such file or directory
#include "../../../../lib/libc++/" ARCH_FAMILY_S "/" ARCH_S "/stkl/printkc/printkc.h"
有没有办法成功地将 ARCH_FAMILY_S
和 ARCH_S
附加到我的 #include
指令字符串?
Is there a way to successfully append ARCH_FAMILY_S
and ARCH_S
to my #include
directive string?
推荐答案
您可以使用一系列宏来创建包含文件.不幸的是,我想不出任何更清洁(源内)的方式来做到这一点.这适用于 arm-eabi-none-gcc
v5.4.1.
You can use a series of macros to create your include file. Unfortunately, I can't think of any cleaner (in-source) way of doing this. This works for 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 指令中使用宏?


基础教程推荐
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01