简体   繁体   English

在C ++代码中使用项目属性/宏

[英]Use Project properties/ Macros in c++ code

I am trying to use the OutDir Macro from the Project properties within my c++ file to build a path. 我正在尝试使用c ++文件中“项目”属性中的OutDir宏来构建路径。

But I can't find a way to assign the OutDir content to a variable in my code. 但是我找不到在我的代码中将OutDir内容分配给变量的方法。

I tried this: 我尝试了这个:

#define OUTPUT_DIR $OutDir

I can't seem to use this correctly. 我似乎无法正确使用此功能。

You can specify pre-processor definitions in the "Project Properties->C/C++->Preprocessor->Preprocessor Definitions" list as: 您可以在“项目属性-> C / C ++->预处理器->预处理器定义”列表中指定预处理器定义,如下所示:

OUTPUT_DIR=$(OutDir)

and then you can use that macro in your source code. 然后您可以在源代码中使用该宏。 You may need to textify it first. 您可能需要先将其文本化。 ie

#define TEXTIFY(x) #x

then use it as 然后将其用作

TEXTIFY(OUTPUT_DIR)

see this answer . 看到这个答案 Although looking at this answer , it is possible that VC++ 2017 has some issues with this. 尽管正在寻找这个答案 ,但VC ++ 2017可能与此有关。

I believe you can also add the quotes into the options itself which might be a way round it. 我相信您也可以将引号添加到选项本身中,这也许可以解决问题。

OUTPUT_DIR="$(OutDir)"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM