How can I #ifdef change an environment variable without changing the Xcode project?

I want to define an environment variable outside of Xcode settings. I can do this while performing an environment check, as indicated in Detection, if the iOS application is running in the debugger , but is there a way to do this with a preprocessor macro like this?

#ifdef USER_GRADHA
    // do some stuff
#else
    // do other stuff
#endif

My environment variable is set, but it does not reach the compilation phase of the .m files. I want to accomplish this without changing the macroprocessor of the project preprocessor, because I want the compilation to be different for each user without the need to change it.

+2
source share
2

. . , , Source Trees Xcode , , ( , ).

+2

-, getenv , . .

#include <stdlib.h>
char *ug = getenv("USER_GRADHA");
if (ug) {
  //use the environment variable here
} else {
  //it NULL == undefined env variable (in all likelihood)
}

, , POSIX -D -U. ,

gcc -DUSER_GRADHA=$USER_GRADHA file.c

, undefined, , . ,

if [ $USER_GRADHA ] ; then ug="-D$USER_GADHA"; else ug="-U$USER_GRADHA"; fi
c99 $ug file.c

make .

, Autotools, . Xcode, Autotools ( Autotools - ), , .

0

Source: https://habr.com/ru/post/1615994/


All Articles