Thread overview
Windows static linking question
Apr 27, 2021
frame
Apr 27, 2021
Imperatorn
Apr 27, 2021
frame
Apr 27, 2021
Mike Parker
Apr 27, 2021
frame
Apr 27, 2021
Mike Parker
Apr 27, 2021
frame
Apr 27, 2021
Mike Parker
Apr 27, 2021
frame
April 27, 2021

From my source...

// main.d
pragma(lib, common.lib);
extern (C) void fun(bool something);
// common.d
export extern (C) void fun(bool something) {
    // ...
}

...I'm creating a static linked DLL with this command...

rdmd --build-only -L/DLL -L/OUT:common.dll -m64 -of=common.dll common.d

... and this works.

However, I get a std.file.FileException@std\file.d(991): Attempting to rename file common.dll.tmp to common.dll error every time at compiling because of the -L/OUT argument. But I cannot omit it because it would create and link a common.dll.tmp instead - for whatever reason.

I know there is a -lib switch which also can create a common.lib, but that's obviously not the same as the LIB does not target to the DLL and the code ends just compiled in than linked.

So, is there another switch combo to achieve static linking by creating a LIB-file? Like a -lib -target=?

April 27, 2021

On Tuesday, 27 April 2021 at 06:29:40 UTC, frame wrote:

>

From my source...

// main.d
pragma(lib, common.lib);
extern (C) void fun(bool something);

[...]

Did you mean to use rdmd and not dmd? 🤔

April 27, 2021

On Tuesday, 27 April 2021 at 07:13:16 UTC, Imperatorn wrote:

>

On Tuesday, 27 April 2021 at 06:29:40 UTC, frame wrote:

>

From my source...

// main.d
pragma(lib, common.lib);
extern (C) void fun(bool something);

[...]

Did you mean to use rdmd and not dmd? 🤔

I could not get it working using dmd. It gaves me LNK2001 linker errors. I honestly have no idea what rdmd else applies to the linker (should inspect it with sysinternals).

But this should not have any impact on the LIB-file. I build the EXE also with rdmd and if the LIB-file contains the link to the DLL everything is fine.

April 27, 2021

On Tuesday, 27 April 2021 at 07:41:28 UTC, frame wrote:

> >

Did you mean to use rdmd and not dmd? 🤔

I could not get it working using dmd. It gaves me LNK2001 linker errors. I honestly have no idea what rdmd else applies to the linker (should inspect it with sysinternals).

What is your dmd command line?

April 27, 2021

On Tuesday, 27 April 2021 at 07:55:53 UTC, Mike Parker wrote:

>

On Tuesday, 27 April 2021 at 07:41:28 UTC, frame wrote:

> >

Did you mean to use rdmd and not dmd? 🤔

I could not get it working using dmd. It gaves me LNK2001 linker errors. I honestly have no idea what rdmd else applies to the linker (should inspect it with sysinternals).

What is your dmd command line?

not very different:

dmd -L/DLL -L/OUT:common.dll -m64 -of=common.dll -I=sources common.d
April 27, 2021

On Tuesday, 27 April 2021 at 08:33:23 UTC, frame wrote:

>

On Tuesday, 27 April 2021 at 07:55:53 UTC, Mike Parker wrote:

>

On Tuesday, 27 April 2021 at 07:41:28 UTC, frame wrote:

> >

Did you mean to use rdmd and not dmd? 🤔

I could not get it working using dmd. It gaves me LNK2001 linker errors. I honestly have no idea what rdmd else applies to the linker (should inspect it with sysinternals).

What is your dmd command line?

not very different:

dmd -L/DLL -L/OUT:common.dll -m64 -of=common.dll -I=sources common.d

What specifically are the linker errors? Is it referring to _DLLMainCRTStartup or something else?

Also, I suspect the reason you're getting the renaming errors with rdmd is because you're passing both -L/OUT:common.dll and -of=common.dll. You should only need one of them (same goes for dmd). But I don't think rdmd is intended to actually compile a distributable binary. You should try to get this working with dmd to solve your linker errors.

April 27, 2021

On Tuesday, 27 April 2021 at 08:50:37 UTC, Mike Parker wrote:

>

What specifically are the linker errors? Is it referring to _DLLMainCRTStartup or something else?

Various "unresolved external symbol", mostly
..._ClassZ,
...__ModuleInfoZ,
..._initZ from my classes and functions
but also _D3std5regex__T8CapturesTAyaZQo6__initZ

>

Also, I suspect the reason you're getting the renaming errors with rdmd is because you're passing both -L/OUT:common.dll and -of=common.dll.

No, it's caused by -L/OUT only. -of is redudant here indeed, but doesn't change anything.

April 27, 2021

On Tuesday, 27 April 2021 at 10:43:20 UTC, frame wrote:

>

On Tuesday, 27 April 2021 at 08:50:37 UTC, Mike Parker wrote:

>

What specifically are the linker errors? Is it referring to _DLLMainCRTStartup or something else?

Various "unresolved external symbol", mostly
..._ClassZ,
...__ModuleInfoZ,
..._initZ from my classes and functions
but also _D3std5regex__T8CapturesTAyaZQo6__initZ

>

Also, I suspect the reason you're getting the renaming errors with rdmd is because you're passing both -L/OUT:common.dll and -of=common.dll.

No, it's caused by -L/OUT only. -of is redudant here indeed, but doesn't change anything.

So you have more than just common.d? You need to compile and link all of your source modules. The big -I is for imports, for the compiler to know what symbols are available. You will also need to either include all of the source files on the command line OR specify -i, which will tell the compiler to compile all imported files except the std namespace. rdmd does that by default.

April 27, 2021

On Tuesday, 27 April 2021 at 11:08:29 UTC, Mike Parker wrote:

>

So you have more than just common.d? You need to compile and link all of your source modules. The big -I is for imports, for the compiler to know what symbols are available. You will also need to either include all of the source files on the command line OR specify -i, which will tell the compiler to compile all imported files except the std namespace. rdmd does that by default.

Indeed, rdmd passes some other files too. Ahh.. this makes sense now. I know the option but I always thought it's enabled on default. Thanks!