digitalmars.D.learn - Additional path for libs
- Heinz (22/22) Feb 23 2011 Hey!
- Andrej Mitrovic (7/8) Feb 23 2011 See this:
- Heinz (9/9) Feb 24 2011 Andrej,
- Andrej Mitrovic (40/40) Feb 24 2011 My bad. DMD uses sc.ini (on windows) to set the LIB path, which will
- Andrej Mitrovic (6/6) Feb 23 2011 One more thing:
- Bekenn (13/13) Feb 26 2011 Apologies for the late reply, but this could help:
Hey! May be a silly situation but i'm trying to append a search path for libraries from the command line. I'm running under win32 with DMD/OPTLINK and i use a batch file for compilation of my project. Adding the path to sc.ini won't help because the project' sources might be moving around in different machines and folders so i'm trying to set a path relative to the sources when invoking dmd. Copying sc.ini to the source path won't help much because DMD might be in different locations at other machines and also the idea is not to mess with the config file. Setting the LIB enviroment variable doesn't produce a positive result. Here's my batch file: --------------------------------------------------- echo on set LIB=..\lib dmd -O -release -inline -ofdemo.exe -I..\import main.d main.def pause --------------------------------------------------- The libs are called from sources with pragma(lib, "mylib.lib"); Any tips on how to accomplish this, if possible? BIG THANKS
Feb 23 2011
See this: http://www.digitalmars.com/ctg/ctgLinkSwitches.html#scanlib You pass switches to the linker via -L, so the switch might be: dmd -L/SCANLIB Of course you would have to update the LIB environment variable in command line, or via a batch file before calling DMD:set lib=C:\DirWithLibFiles\;%lib%I think that should do it, although I haven't tested it.
Feb 23 2011
Andrej, Thanks for the reply. I already tried /SCANLIB before with no success. I couldn't find a solution so i'm sticking to the classic method of declaring each lib in the dmd command line. Lib paths at command line could be added to OPTLINK, it should work in the same way the DMD -I argument work. This is beyond our scope anyway, this is a task for Walter. Thanks anyway.
Feb 24 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).
Feb 24 2011
One more thing: If your lib files are relative to your current working directory, then you can just pass them to DMD. E.g. if your lib file is under the subdir folder of your current working dir you can just use: dmd main.d subdir\mylibfile.lib But maybe you knew that already.
Feb 23 2011
Apologies for the late reply, but this could help: As you've already seen in the other replies, the provided sc.ini file is confounding your attempts at setting the LIB environment variable. However, OPTLINK's search path for sc.ini includes the current directory, so if you're reluctant to alter the original file, you can just create an empty sc.ini in the current directory. You are then free to redefine LIB and DFLAGS to whatever you like. Here's an excerpt from one of my makefiles (I use Microsoft's NMAKE): $(EXECUTABLE) : sc.ini $(SOURCES) $(D) $(SOURCES) $(LIBS) $(DFLAGS) $(DEXEFLAGS) move /y "$(APPNAME).map" $( D) > NUL sc.ini : copy NUL sc.ini
Feb 26 2011