running my program with shared libraries
Marc Schütz" <schuetzm at gmx.net>
Marc Schütz" <schuetzm at gmx.net>
Sun Apr 6 03:17:33 PDT 2014
On Sunday, 6 April 2014 at 02:49:15 UTC, Adam D. Ruppe wrote:
> On Sunday, 6 April 2014 at 00:12:00 UTC, Harpo wrote:
>> Then in a runner script I have this.
>>
>> LD_LIBRARY_PATH=. ./main
>
> This kind of thing is common in Linux, in fact, a lot of Linux
> software consists of a runner script that sets LD_LIBRARY_PATH
> and a separate binary file and its library .so files that is
> the actual application.
>
> LD_LIBRARY_PATH tells it where to find the shared library
> files. Without it, the system only searches the global
> directories like /usr/lib.
You can also use the linker flag "-rpath" to hard-code the search
path in the executable.
dmd your_file.d -L-rpath -L'$ORIGIN/.'
The $ORIGIN (with quotation marks around it to keep it from being
expanded) is important. It means the linker should interpret the
path relative to the location of your executable, instead of
relative to whatever the current directory happens to be. (The
latter is a security risk, because an adversary might trick the
user to run your executable from their own directory, where they
have placed a manipulated copy of the shared library.)
More information about the Digitalmars-d-learn
mailing list