[英]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.