C近拍 - 动态的#include [英] C Macro - Dynamic #include

查看:234
本文介绍了C近拍 - 动态的#include的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何建立使用GCC #include语句的变量字符串。

I'm trying to figure out how to build a variable string for the #include statement using GCC.

的想法是,我已经写了各模块的话,我想包括作为标题,动态生成的 C 来源,先前在构建过程中创建的。

The idea is that for each source module I have written, I want to include as a header, a dynamically generated C source, that was created earlier in the build process.

生成该文件是不是一个问题。包括它,不幸的是,

Generating this file is not an issue. Including it, unfortunately, is.

我至今是(identities.h):

What I have so far is (identities.h):

// identities.h

# define PASTER2(str)  #str
# define PASTER(str)   PASTER2(str ## .iden)
# define EVALUATOR(x)  PASTER(x)

# define IDENTITIES_FILE EVALUATOR(__FILE__)
# include IDENTITIES_FILE

在理想情况下,这将被用于像这样(main.c中):

Ideally, this would be used like so (main.c):

//main.c

# include "identities.h"

int main() {return 0;}

这将在单次通过由preprocessor扩大汇编之前,得​​到

Which would be expanded in a single pass by the preprocessor before compilation to yield:

//main.c (preprocessed)

# include "main.c.iden"

int main() {return 0;}

间接的两级我使用(贴膜和EVALUATOR)是<一个结果href=\"http://stackoverflow.com/questions/1489932/c-$p$pprocessor-and-concatenation/1489985#1489985\">this帖子。

不幸的是,这是行不通的,我留下了错误:

Unfortunately, this is not working and I am left with the error:

obj/win32/dbg/main.o
In file included from main.c:1:0:
identities.h:42:1: error: #include expects "FILENAME" or <FILENAME>

我觉得问题是,包括语句丢失报价..任何想法?

I think the problem is that the include statement is missing quotes.. Any ideas?

推荐答案

怎么样从的升压preprocessor库。它是专门做给周围添加一个名字报价。

What about BOOST_PP_STRINGIZE from the Boost Preprocessor library . It is specifically made to add quotes around a name.

这篇关于C近拍 - 动态的#include的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆