我需要ANDROID_HOME在 OSX 上获取环境变量的值(在.bash_profile中设置)。我可以通过echo $ANDROID_HOME在终端中输入来验证它的存在。
这是代码:(Xcode项目)
void testGetEnv(const string envName) {
char* pEnv;
pEnv = getenv(envName.c_str());
if (pEnv!=NULL) {
cout<< "The " << envName << " is: " << pEnv << endl;
} else {
cout<< "The " << envName << " is NOT set."<< endl;
}
}
int main() {
testGetEnv("ANDROID_HOME");
}
输出总是The ANDROID_HOME is NOT set.. 我不认为我在getenv()这里使用正确。要么,要么.bash_profilegetenv()在被调用时无效。
我错过了什么?