www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Linking with DMD

reply "Anonymous" <herr.pilsner yahoo.de> writes:
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
Jun 21 2012
next sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 6/21/2012 10:48 AM, Anonymous wrote:
 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...
main() cannot function as the start address of a program. Things must be set up first, and __acrtused_con pulls in the code that does that. But that code must exist in a library.
Jun 21 2012
prev sibling next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 6/21/2012 10:48 AM, Anonymous wrote:
 And that I can link to them by simply specifying the
 DLL file... not having to find a matching lib file on the internet...
DLL files contain insufficient information to link successfully to them.
Jun 21 2012
parent reply "Anonymous" <herr.pilsner yahoo.de> writes:
On Thursday, 21 June 2012 at 18:06:12 UTC, Walter Bright wrote:
 On 6/21/2012 10:48 AM, Anonymous wrote:
 And that I can link to them by simply specifying the
 DLL file... not having to find a matching lib file on the 
 internet...
DLL files contain insufficient information to link successfully to them.
GCC (MinGW) is able to do this...
Jun 21 2012
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 6/21/2012 11:14 AM, Anonymous wrote:
 On Thursday, 21 June 2012 at 18:06:12 UTC, Walter Bright wrote:
 On 6/21/2012 10:48 AM, Anonymous wrote:
 And that I can link to them by simply specifying the
 DLL file... not having to find a matching lib file on the internet...
DLL files contain insufficient information to link successfully to them.
GCC (MinGW) is able to do this...
For example, many names in Windows DLLs are: _foo 16 which means there are 16 bytes worth of parameters. However, there's zero information on how many parameters there are or what their types are.
Jun 21 2012
parent "Anonymous" <herr.pilsner yahoo.de> writes:
On Thursday, 21 June 2012 at 19:42:46 UTC, Walter Bright wrote:
 On 6/21/2012 11:14 AM, Anonymous wrote:
 On Thursday, 21 June 2012 at 18:06:12 UTC, Walter Bright wrote:
 On 6/21/2012 10:48 AM, Anonymous wrote:
 And that I can link to them by simply specifying the
 DLL file... not having to find a matching lib file on the 
 internet...
DLL files contain insufficient information to link successfully to them.
GCC (MinGW) is able to do this...
For example, many names in Windows DLLs are: _foo 16 which means there are 16 bytes worth of parameters. However, there's zero information on how many parameters there are or what their types are.
But you declare it in your code like this: extern (Windows) int foo(int a, void* b, void* c, uint d);
Jun 21 2012
prev sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 06/21/2012 07:48 PM, Anonymous wrote:
 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...
 ...
If linking in the runtime is disabled explicitly, linker errors are to be expected.
Jun 21 2012