- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How come on my Mac OS X, when I create a dylib file and run my executable it knows to look ion the same folder for the dylib, but on Linux when it looks for the .so it does not know where to look for it?
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's generally considered undesirable (vulnerable to malicious hacks) to include current directory in PATH and LD_LIBRARY_PATH by default (at least under bash, which often is the default shell). You can read further about this by starting up your search engine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As tim18 said, the current directory shouldn't be added to the $PATH, and some commands even enforce the rule (e.g., find). The $LD_LIBRARY_PATH is expected to be used for compilation purposes only, but its use is discouraged at runtime.
However, the directory in which the executable lies can be added to the runtime path during the linking. You can make the compiler pass it as an option to the linker, with the following flags:
-Wl,-z,origin -Wl,-rpath,\$ORIGIN

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page