digitalmars.D.learn - Windows static linking question
- frame (28/28) Apr 26 2021 From my source...
- Imperatorn (2/9) Apr 27 2021 Did you mean to use rdmd and not dmd? 🤔
- frame (7/18) Apr 27 2021 I could not get it working using dmd. It gaves me LNK2001 linker
- Mike Parker (2/6) Apr 27 2021 What is your dmd command line?
- frame (6/15) Apr 27 2021 not very different:
- Mike Parker (9/25) Apr 27 2021 What specifically are the linker errors? Is it referring to
- frame (8/13) Apr 27 2021 Various "unresolved external symbol", mostly
- Mike Parker (8/21) Apr 27 2021 So you have more than just common.d? You need to compile and link
- frame (4/11) Apr 27 2021 Indeed, rdmd passes some other files too. Ahh.. this makes sense
From my source... ```d // main.d pragma(lib, common.lib); extern (C) void fun(bool something); ``` ```d // 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=```?
Apr 26 2021
On Tuesday, 27 April 2021 at 06:29:40 UTC, frame wrote:From my source... ```d // main.d pragma(lib, common.lib); extern (C) void fun(bool something); ``` [...]Did you mean to use rdmd and not dmd? 🤔
Apr 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: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.From my source... ```d // main.d pragma(lib, common.lib); extern (C) void fun(bool something); ``` [...]Did you mean to use rdmd and not dmd? 🤔
Apr 27 2021
On Tuesday, 27 April 2021 at 07:41:28 UTC, frame wrote:What is your dmd command line?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).
Apr 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:not very different: ``` dmd -L/DLL -L/OUT:common.dll -m64 -of=common.dll -I=sources common.d ```What is your dmd command line?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).
Apr 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: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.On Tuesday, 27 April 2021 at 07:41:28 UTC, frame wrote:not very different: ``` dmd -L/DLL -L/OUT:common.dll -m64 -of=common.dll -I=sources common.d ```What is your dmd command line?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).
Apr 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.
Apr 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: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.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.
Apr 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!
Apr 27 2021