export DYLD_LIBRARY_PATH="/opt/local/lib"
I am looking at this line and there are many questions in my head. I am newbie with MacPorts and I am learning to use it but after gone through many topics, tutorials and articles, I get confused now.
Please correct me if I am wrong in next:
Mac Ports installs library into different directory /opt/local/lib
rather than /usr/local/lib
.
I get this idea about it, but I encounter the problem if I want to use MacPorts
I currently have two projects A and B on my machine.
Project A is working well with the default library stay at /usr/local/lib
,
while project B is the project that I want to point the environment to /opt/local/lib
to build properly with libraries that are installed by Mac Ports.
How could I can set the environment DYLD_LIBRARY_PATH to /opt/local/lib for project B but it does not affect project A next time I rebuild it? (May I be wrong about this point?)
I saw someone wrote that we can use the export environment_var_name=value to achieve the purpose, does it affect all projects in my machine next time I back to rebuild them? (May I be wrong about this point?)
Other people told that we can set the environment variable for a project specifically by adding/modifying the value on the project scheme on Xcode. Is it correct way to do that?
If my questions could lead to the long answer, please feel free to expose your opinion.
DON'T do that.
You should never ever ever need to set DYLD_LIBRARY_PATH outside of testing (and in very limited cases during a build). It should never be used in production code, never shipped to users, and never recommended to people who don't have a deep understanding of how dyld works. It is NOT analogous to LD_LIBRARY_PATH in ld.so. It will cause you tons of problems if you set it in your .bashrc or other init script which won't be apparent immediately. It will cause MacPorts libraries to be used instead of system libraries which will cause codesignature verification issues, binary compatibility issues, and aborts at process launch due to library version mismatch.
If you want to use the MacPorts libraries, link your project against them instead of the ones you've installed in /usr/local by setting up your header search path and library search path.
Furthermore, your use of /usr/local may have caused issues with your MacPorts install because /usr/local is part of the default search path.