简体   繁体   English

将值从Xcode中的运行脚本传递给编译

[英]Pass value from run-script in Xcode to compilation

Is it possible to define a new environment variable in X code, and pass it as a flag when compiling source C/C++ file in Xcode ? 是否可以在X代码中定义新的环境变量,并在Xcode中编译源C / C ++文件时将其作为标志传递?

I've tried to add "Run script" phase prior to "Compile Sources" in my project "Build Phases" 我尝试在我的项目“构建阶段”中的“编译源代码”之前添加“运行脚本”阶段

Here's the script I run, where I get the value of 'X': 这是我运行的脚本,在这里我得到'X'的值:

在此处输入图片说明

And in "Compile Sources" I've added 'X' to "Other C Flags" 在“编译源”中,我在“其他C标志”中添加了“ X”

在此处输入图片说明

But unfortunately, X is undefined in this scope, so X_FOR_APP is empty. 但不幸的是,在此范围内未定义X,因此X_FOR_APP为空。 What am I doing wrong here? 我在这里做错了什么?

Ok, so I haven't found exactly what I was needed, but here's a nice workaround. 好的,所以我还没有找到我真正需要的东西,但这是一个不错的解决方法。

Instead of passing macro definitions via the compilation command , it's possible to create an output header file from the preceding "run script" phase with all the necessary definitions which will be inserted to this header from the script. 不必通过编译命令传递宏定义,而是可以从前一个“运行脚本”阶段创建一个输出头文件,其中包含所有必需的定义,这些定义将从脚本插入到该头文件中。

This "tells" the next build phases (compile sources) that the file can be included although it's not yet existing. 这“告诉”了下一个构建阶段(编译源),尽管该文件尚不存在,但仍可以包含该文件。

During compilation, we first conduct "run script" and the file is created under $(DERIVED_FILE_DIR)/myheader.h , ready to be included while running the compilation itself on the source file. 在编译期间,我们首先执行“运行脚本”,然后在$(DERIVED_FILE_DIR)/myheader.h下创建文件,准备在源文件上运行编译本身时将其包含在内。

在此处输入图片说明

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

相关问题 将函数返回值传递给参考参数会导致GCC中的编译错误 - Pass function return value to reference parameter cause compilation error in GCC 使用Xcode进行SoundTouch编译? - SoundTouch compilation with Xcode? Xcode:严格的C编译? - Xcode: strict C compilation? 从方法堆栈编译中按值返回实例 - Return instance by value from a method stack compilation 使用Shell脚本中的-D名称编译选项 - Using the -D name compilation option from a shell script wxDVC 渲染器的 Xcode 编译失败 - Xcode compilation failure for wxDVC renderer Xcode中DEBUG标识符的编译错误 - Compilation error on the DEBUG identifier in Xcode 当我将字符串从.mm文件传递到.cpp文件时,程序可以正常编译,但是在运行时,我在Xcode中收到错误“ EXC_BAD_ACCESS” - When I pass a string from .mm file to .cpp file , the program compiles fine but at the run time I get an error “EXC_BAD_ACCESS” in Xcode 如何使用cmake脚本从命令行中选择用于编译C ++代码的xcode版本 - how to choose the version of xcode for compilation C++ codes from command line with cmake scripts 如何防止std标头(在Xcode中)内发生编译错误? - How can I prevent compilation errors from occurring inside std header (in Xcode)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM