通过SetEnvironmentVariable进行的更改不会在使用getenv的库中生效 [英] Changes via SetEnvironmentVariable do not take effect in library that uses getenv
问题描述
但是,库调用 getenv
来设置它需要设置环境变量才能使库正常工作,所以我使用 Environment.SetEnvironmentVariable
,但库无法检索我设置的值。
getenv在启动时生成进程的环境变量块的副本。通过SetEnvironmentVariable进行的任何后续更改都不会反映在getenv使用的变量块中。您将需要固定setenv函数以调整后续getenv调用中反映的值。
请参阅: http://msdn.microsoft.com/en-us/library/tehxacec(VS.71).aspx
getenv和_putenv使用全局变量_environ指向的环境的副本来访问环境getenv仅对运行时可访问的数据结构运行,时间库,而不是由操作系统为进程创建的环境段,因此使用envp参数为main或wmain的程序可能会检索无效信息。
I have a simple c# application that is binding to a library compile with mingnu compiler toolset. I can easily call the functions in the library without issue.
However the library calls getenv
to set itself up this environment variable needs to be set for the library to work correctly so I am using Environment.SetEnvironmentVariable
however the library cannot retrieve the value I have set.
getenv makes a copy of the environment variable block of the process on startup. Any subsequent changes via SetEnvironmentVariable will not be reflected in the block of variables used by getenv. You will need to pinvoke the setenv function to have the adjusted the value reflected in subsequent getenv calls.
See: http://msdn.microsoft.com/en-us/library/tehxacec(VS.71).aspx
"getenv and _putenv use the copy of the environment pointed to by the global variable _environ to access the environment. getenv operates only on the data structures accessible to the run-time library and not on the environment "segment" created for the process by the operating system. Therefore, programs that use the envp argument to main or wmain may retrieve invalid information."
这篇关于通过SetEnvironmentVariable进行的更改不会在使用getenv的库中生效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!