Linking with DMD

Anonymous herr.pilsner at yahoo.de
Thu Jun 21 10:48:52 PDT 2012


So I really think improvements could be made on how you link your 
code when compiling it with DMD...

I want to have the complete control over which libraries i link 
my program to...

Actually, i'm not yet planning on using either phobos or tango. 
(I would maybe use one of those when i notice, that one of those 
libraries offers something that i would like to use, because 
otherwise my executable file would unnecessarily blow up in size, 
right?)

So I ended up downloading the zip-archive of DMD and extracting 
only the parts i need:

- Windows DMD without any lib files (only the contents of the 
\windows\bin\ folder)
- druntime (object.d, ...)

The folder which was the \windows\bin\ folder is now my main DMD 
folder

I changed the sc.ini file so that it now only

- looks for lib files in an empty "lib" folder i created inside 
this main DMD folder
- imports the druntime source files (i exported everything inside 
/src/druntime/src/ into an "import" folder inside the main DMD 
folder and renamed object_.d to object.d)

Now when i try to compile a file with only
- a module name declaration
- and an empty void main(){} function (without extern linking)

it says:

OPTLINK : Warning 23: No Stack
Error 42: Symbol Undefined _main
Error 42: Symbol Undefined __acrtused_con
OPTLINK : Warning 134: No Start Address

I would really like seeing this working...

Also i would like to be able to link to DLL files directly 
without having to create or find matching lib files...

So that i could write on the command line something like:

dmd mysource.d C:\Windows\system32\kernel32.dll 
C:\WINXP\system32\Winmm.dll C:\WINXP\system32\Gdi32.dll

And in my program i declare the functions i want to use with 
extern linkage without body.

Is this somehow possible? I really like many things D offers like 
nested functions, closures, modules, how it doesn't pollute your 
namespace because of the possibilities you have when importing 
other modules...

But i think the linking process still has to be cut down and made 
simple and straightforward.

It works when I copy all the lib files from \windows\lib into my 
lib folder... so i guess it links to lib files which I haven't 
even specified on the command line.

This should all be made much more straightforward... So that I 
can link only to the libraries i want to... And that I can link 
to them by simply specifying the DLL file... not having to find a 
matching lib file on the internet...

Because otherwise i don't think D is much better than a bloated 
java virtual machine or stuff like that...

So, I'm really curious about the opinions on that


More information about the Digitalmars-d mailing list