Domanda

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 ?

È stato utile?

Soluzione

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).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top