Additional path for libs

Andrej Mitrovic andrej.mitrovich at gmail.com
Thu Feb 24 11:34:50 PST 2011


My bad. DMD uses sc.ini (on windows) to set the LIB path, which will
overwrite anything already in the LIB variable once you invoke DMD.

What you can do is change sc.ini (or the equivalent .conf file on
linux), so it appends and not overwrites the LIB path.

e.g. before:
[Environment]
LIB="%@P%\..\lib";\dm\lib;

after:
[Environment]
LIB="%@P%\..\lib";\dm\lib;%LIB%

After modifying DMD\DMD2\Windows\Bin\sc.ini I can test it in a project:

D:\test\main.d:
module main;
import std.stdio;
pragma(lib, "mylib.lib");
extern(C) int foo(int x, int y);
void main()
{
    assert(foo(5, 5) == 10);
}


D:\test\libfolder\mylib.d:
extern(C) int foo(int x, int y)
{
    return x + y;
}

I compile my lib:
D:\test\libfolder\dmd -lib mylib.d

Then I run this batch file from D:\test\:
build.bat:
set LIB=%cd%\libfolder;%LIB%
dmd main.d

D:\test\build.bat
Our project compiles.

D:\test\main
The assert passes.

I don't really know why sc.ini is configued to /overwrite/ the LIB
variable, when it can just prepend any paths that it requires before
the rest of the contents of LIB. This shouldn't cause any conflicts.

You'll have to ask Walter about why sc.ini is configured this way (I'm
curious too).


More information about the Digitalmars-d-learn mailing list