views:

452

answers:

2

Hi,

I'm using VS 2008 and compile my application with Multi-threaded Debug (/MTd). At link time I receive the following error:

error LNK2001: unresolved external symbol __environ

Where the symbol is defined?

Thanks Dima

+2  A: 

When you are using /Md (or variants), the symbols _environ and _wenviron are replaced by function calls. You need to track down the code that uses these (obsolete and deprecated) symbols, and make them use the proper function names. I found lots of people with the same problem as you in google also.

I found some more detail here:

Polling _environ in a Unicode context is meaningless when /MD or /MDd linkage is used. For the CRT DLL, the type (wide or multibyte) of the program is unknown. Only the multibyte type is created because that is the most likely scenario.

If you change the use of the symbol _environ to the wide character version _wenviron, your original code will probably work.

1800 INFORMATION
Ok, so I need to use getenv_s, _wgetenv_s and _putenv_s, _wputenv_s. But what if I want iterate over all environment variables?
dimba
I added a bit more detail, it looks like you should use the _wenviron symbol if you are using /Md
1800 INFORMATION
+1  A: 

As the documentation describes, _environ is declared in Stdlib.h and implemented in the crt lib.

Therefore you might have a problem with linking with this library, or maybe it's picking up the wrong lib (try checking your build paths).

Alan