开发者

Problems with using setenv and then making the dlopen call

I am using setenv to set DYLD_LIBRARY_PATH so when I do a dlopen() it will have the correct paths to find my .dylib, but when I do the dlopen() it doesn't seem to search the paths that I added to DYLD_LIBRARY_PATH.

From what I can 开发者_开发百科gather my changes to DYLD_LIBRARY_PATH won't take effect until a re-execute my process happens. Is this correct?

Also if that is correct, is there a way to set DYLD_LIBRARY_PATH and having my changes work with out doing a reset of my process.

Oh yeah I writing this code on MAC OSX.

Thanks in advance.


I don't know about Mac OS, but on Linux, the loader reads the value of getenv("LD_LIBRARY_PATH") once, and saves it away, long before the first instruction of your executable runs. Subsequent modification of LD_LIBRARY_PATH by the program only affects any children it execve()s, but not the process itself. I imagine it's similar on Mac OS.

The usual way around this is to either re-execve the proces (Java does this), or to use a shell wrapper which sets the environment and then exec's the real binary (Firefox does that).

There might be a Mac OS specific way to update the library search path, though Google doesn't seem to find any matches. I am pretty sure there isn't any such mechanism on Linux.


The answer to my question is no you can't use setenv without doing a re-execute of the process on LD_LIBRARY_PATH for the environmental variable to take an effect on dlopen.

I found out that you should use @exectuable_path, @loader_path, or @rpath as an install name path on my .dylb is this way you can do a relative path search on your .dylibs from dlopen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜