0

When I checked the man-page for dlopen on iOS it says:

When path contains a slash (i.e. a full path or a partial path) dlopen() searches the following the following until it finds a compatible Mach-O file: $DYLD_LIBRARY_PATH (with leaf name from path ), current working directory (for partial paths), $DYLD_FALLBACK_LIBRARY_PATH (with leaf name from path ).

but according to POSIX (Open Group):

The file argument is used to construct a pathname to the object file. If file contains a slash character, the file argument is used as the pathname for the file. Otherwise, file is used in an implementation-defined manner to yield a pathname.

So if you follow POSIX you could use dlopen("/path/to/lib", 0) to open precisely that file, but according to the iOS documentation it would search for a Mach-O file named lib in $DYLD_LIBRARY_PATH, current directory and finally $DYLD_FALLBACK_LIBRARY_PATH.

If I really want to open just /path/to/lib under iOS and not any (possibly malign) lib found in the search path, what could I do?

(If I understand it correctly POSIX allows you to use a relative path too. Would that imply that it's a path relative to the current working directory then?)

7
  • if you are controlling the library, you could set have a function that only you set.. and and exit if you can't link it Mar 2, 2016 at 14:51
  • and if you dont, then you could just check the version.. Mar 2, 2016 at 14:51
  • I think the idea of searching $DYLD_LIBRARY_PATH is for security so you cannot open and run any library you liked at runtime. I am not sure what part of POSIX you are quoting (I guess the manpage to dlopen()?) but those systems (including OSX) are more relaxed about loading dynamic libraries. Whenever a relative file is used it's generally always relative to the current working directory, yes, as that is used as the base for such file ops.
    – trojanfoe
    Mar 2, 2016 at 15:07
  • @trojanfoe I'm not sure I agree about that. The POSIX standard says dlopen should open a specific library in this case, while iOS man page says it will open a "random" library based on what happens to be in DYLIB_LIBRARY_PATH and DYLD_FALLBACK_LIBRARY_PATH and which the current working directory happens to be. To me it does not sound more secure or less relaxed, it sounds rather the opposite. Btw the part of POSIX I'm quoting is the description of dlopen at Open Group.
    – skyking
    Mar 3, 2016 at 6:10
  • @GradyPlayer But if that fails I don't get to open the library I would want to open...
    – skyking
    Mar 3, 2016 at 6:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.