문제

I have to port an existing code written in C and C++ to iOS.

This code, at some point, uses the environ variable to access all the environment variables.

When compiling this code with the iOS compiler toolchain, it complains that environ is not a defined symbol. I couldn't find any header that would provide it or any suitable alternative.

Unfortunately, environ is used to get all the environment variables and pass them to a sub-routine. That is, getenv() is not an option, since we don't know what environment variables to check for.

Is there a way in C or C++ code, with the iOS compiler toolchain, to access to the environ variable ? Or do you know any alternative solution ?

도움이 되었습니까?

해결책

The environ variable must be declared in the user program, in your C code. So just declare it like this before accessing:

extern char **environ;

You may also find this article about iOS environment helpful (it has an example project as well).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top