On Mac/Linux, library calls to open files (fopen, etc..) with relative paths in executables are relative to the current directory of the terminal and if I double click from folder relative to the user home directory (I think). How do I make relative paths relative to the executable for both instances (running on terminal and double clicking from folder) without changing any code? I think it has something to do with environment variables but I'm not sure.
Asked
Active
Viewed 721 times
1
-
You need something to [chdir(2)](http://man7.org/linux/man-pages/man2/chdir.2.html) to the wanted directory, and that something is probably not an environment variable. Perhaps making a shell wrapping a `cd` and the real program might help. – Basile Starynkevitch Jun 01 '13 at 23:08
1 Answers
0
Try to set dependency path relative to @executable_path or @loader_path using install_name_tool
. See this question for some additional info on how to use it.
Use otool -L <your_executable>
to see all dependencies.
For the info about @executable_path and @loader_path see man dyld