lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Steve Dekorte wrote:

Don't some platforms require the executable to know the absolute path to the shared lib while not providing the app with info about the path the executable?(Linux?) So the shared libs are essentially required to be in system folders and therefore seriously complicate user-level applications


I've worked around this in my project using a very ugly but
effective hack. Since you need platform specific code to load
the libraries anyway it may not be a big deal.

In a nutshell:

- Grab argv[0], split off the path, and chdir() there

- getcwd() to get the full path back

- Use getenv()/putenv() to add the path to LD_LIBRARY_PATH
  (or wherever is appropriate for the system)

Here comes the ugly part:

- Call execve() to restart the process under the new environment

Shared libraries located in the same directory as the exec
will be found and loaded. Tested on Linux and BeOS (don't
need it for Win32 which has this behavior by default).

Jason