gpt4 book ai didi

c++ - 如何在#include 指令中使用宏?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:39:51 27 4
gpt4 key购买 nike

我对如何在 #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++/: No such file or directory  #include "../../../../lib/libc++/" ARCH_FAMILY_S  "/" ARCH_S  "/stkl/printkc/printkc.h"

有没有办法将 ARCH_FAMILY_SARCH_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)

关于c++ - 如何在#include 指令中使用宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40062883/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com