digitalmars.D.learn - Trying to create a trivial 64 bit D Lang DLL on a Windows 10 machine
- WhatMeWorry (33/38) Sep 29 2020 module user;
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (4/7) Sep 30 2020 it is better to use this template
- user1234 (6/16) Oct 01 2020 yeah that's the problem, check [0] OP. The author makes
- WhatMeWorry (3/21) Oct 01 2020 Yes, but shouldn't the /NOENTRY option take care of that. Say, I
- kinke (8/12) Oct 01 2020 Your little example has 2 problems, the first being an
- WhatMeWorry (24/40) Oct 01 2020 total = 12
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (3/11) Oct 01 2020 1) try running your commands in Visual Studio Native x64 CMD.
- WhatMeWorry (7/24) Oct 02 2020 Yes, I've been doing that.
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (23/48) Oct 02 2020 Here are the steps I used with success:
- Imperatorn (2/24) Oct 02 2020 Did you create a D-partition just for D. Pro
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (2/25) Oct 02 2020 Haha. Yes my c compiler is also located at c:\c
- rikki cattermole (3/4) Oct 02 2020 You can mount directories as a drive on Windows.
- =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= (2/5) Oct 01 2020 As example, DLL: https://github.com/vitalfadeev/dlang-dll
module user; export { int myAddSeven(int a, int b); } void main() { int total = myAddSeven(2, 3); }dmd -m64 -c user.dmodule mydll; export extern(D) { int myAddSeven(int a, int b) { return a+b+7; } /* <-- function body */ }dmd -c -shared -m64 mydll.dlink mydll.obj /DLL /NOENTRYMicrosoft (R) Incremental Linker Version 14.27.29111.0 Copyright (C) Microsoft Corporation. All rights reserved. Creating library mydll.lib and object mydll.explink user.obj /implib:mydll.libMicrosoft (R) Incremental Linker Version 14.27.29111.0 Copyright (C) Microsoft Corporation. All rights reserved. LINK : fatal error LNK1104: cannot open file 'phobos64.lib' or when I give the linker phobos64.liblink user.obj /implib:mydll.lib /LIBPATH:C:\D\dmd2\windows\lib64Microsoft (R) Incremental Linker Version 14.27.29111.0 Copyright (C) Microsoft Corporation. All rights reserved. user.obj : error LNK2019: unresolved external symbol __imp__D4user10myAddSevenFiiZi referenced in function _Dmain phobos64.lib(stacktrace_1be8_3e5.obj) : error LNK2019: unresolved external symbol snprintf referenced in function _D4core3sys7windows10stacktrace10StackTrace13resolveNoSyncFAxmZAAa phobos64.lib(demangle_c96_79b.obj) : error LNK2001: unresolved external symbol snprintf phobos64.lib(parseoptions_e2c_21b.obj) : error LNK2001: unresolved external symbol snprintf phobos64.lib(parseoptions_e2c_21b.obj) : error LNK2019: unresolved external symbol sscanf referenced in function _D4core8internal12parseoptions5parseFNbNiAxaKANgaKfQkZb user.exe : fatal error LNK1120: 3 unresolved externals
Sep 29 2020
On Tuesday, 29 September 2020 at 21:22:21 UTC, WhatMeWorry wrote:module user; export { int myAddSeven(int a, int b); } [...]it is better to use this template https://github.com/dlang/dmd/tree/master/samples/mydll You don't have a DllMain.
Sep 30 2020
On Wednesday, 30 September 2020 at 11:45:53 UTC, Ferhat Kurtulmuş wrote:On Tuesday, 29 September 2020 at 21:22:21 UTC, WhatMeWorry wrote:yeah that's the problem, check [0] OP. The author makes commercial dll on windows so he knows what he speaks about [0] https://forum.dlang.org/post/mscgsclxwtjcferfxoet forum.dlang.orgmodule user; export { int myAddSeven(int a, int b); } [...]it is better to use this template https://github.com/dlang/dmd/tree/master/samples/mydll You don't have a DllMain.
Oct 01 2020
On Thursday, 1 October 2020 at 09:22:29 UTC, user1234 wrote:On Wednesday, 30 September 2020 at 11:45:53 UTC, Ferhat Kurtulmuş wrote:Yes, but shouldn't the /NOENTRY option take care of that. Say, I just want to make a DLL of simple functions.On Tuesday, 29 September 2020 at 21:22:21 UTC, WhatMeWorry wrote:yeah that's the problem, check [0] OP. The author makes commercial dll on windows so he knows what he speaks about [0] https://forum.dlang.org/post/mscgsclxwtjcferfxoet forum.dlang.orgmodule user; export { int myAddSeven(int a, int b); } [...]it is better to use this template https://github.com/dlang/dmd/tree/master/samples/mydll You don't have a DllMain.
Oct 01 2020
On Thursday, 1 October 2020 at 20:03:19 UTC, WhatMeWorry wrote:Yes, but shouldn't the /NOENTRY option take care of that. Say, I just want to make a DLL of simple functions.Your little example has 2 problems, the first being an incompatible extern(D) ex/import (mydll.myAddSeven vs. user.myAddSeven) and the second being an incomplete/wrong linker cmdline. When changing the myAddSeven declarations to extern(C++) (another option being a mydll.di header for the import), it works withdmd -m64 -shared -L/NOENTRY mydll.d dmd -m64 user.d mydll.libFor more details, see also https://wiki.dlang.org/Win32_DLLs_in_D.
Oct 01 2020
On Thursday, 1 October 2020 at 20:28:58 UTC, kinke wrote:On Thursday, 1 October 2020 at 20:03:19 UTC, WhatMeWorry wrote:Thanks all. I've gotten it to work with:Yes, but shouldn't the /NOENTRY option take care of that. Say, I just want to make a DLL of simple functions.Your little example has 2 problems, the first being an incompatible extern(D) ex/import (mydll.myAddSeven vs. user.myAddSeven) and the second being an incomplete/wrong linker cmdline. When changing the myAddSeven declarations to extern(C++) (another option being a mydll.di header for the import), it works withdmd -m64 -shared -L/NOENTRY mydll.d dmd -m64 user.d mydll.libFor more details, see also https://wiki.dlang.org/Win32_DLLs_in_D.dmd -m64 -ofmydll.dll mydll.d -L/NOENTRY -L/DLLdmd -m64 user.d mydll.libuser.exetotal = 12 But then I got cocky and decided to just added a writeln() in the mydll.d file and I've been fighting this link error ever since: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\Hostx64\x64\link.exe /NOLOGO "mydll.obj" /OUT:"mydll.dll" /DEFAULTLIB:phobos64 /NOENTRY /DLL /OPT:NOICF /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\lib\x64" legacy_stdio_definitions.lib /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\ucrt\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\um\x64" Creating library mydll.lib and object mydll.exp mydll.obj : error LNK2019: unresolved external symbol fwrite referenced in function _D3std5stdio__T13trustedFwriteTaZQsFNbNiNePOS4core4stdcQBx6_iobufxAaZm phobos64.lib(object_72_81a.obj) : error LNK2001: unresolved external symbol memcpy phobos64.lib(exception_cf4_fff.obj) : error LNK2001: unresolved external symbol memcpy phobos64.lib(bits_23fa_21c.obj) : error LNK2001: unresolved external symbol memcpy phobos64.lib(gc_2413_a4e.obj) : error LNK2001: unresolved external symbol memcpy phobos64.lib(gc_2415_a03.obj) : error LNK2001: unresolved external symbol memcpy phobos64.lib(gc_2478_432.obj) : error LNK2001: unresolved external symbol memcpy o o o
Oct 01 2020
On Thursday, 1 October 2020 at 21:35:42 UTC, WhatMeWorry wrote:On Thursday, 1 October 2020 at 20:28:58 UTC, kinke wrote:1) try running your commands in Visual Studio Native x64 CMD. 2) try link with msvcrt.lib[...]Thanks all. I've gotten it to work with:[...][...][...]total = 12 [...]
Oct 01 2020
On Thursday, 1 October 2020 at 21:56:46 UTC, Ferhat Kurtulmuş wrote:On Thursday, 1 October 2020 at 21:35:42 UTC, WhatMeWorry wrote:Yes, I've been doing that.On Thursday, 1 October 2020 at 20:28:58 UTC, kinke wrote:1) try running your commands in Visual Studio Native x64 CMD.[...]Thanks all. I've gotten it to work with:[...][...][...]total = 12 [...]2) try link with msvcrt.libThe only msvcrt.lib I can find on my Windows 10 machine is: "C:\Windows Kits\10\Lib\10.0.19041.0\um\x64\ntstc_msvcrt.lib" Also on Microsoft's docs https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-f atures?view=vs-2019 it talks about a ucrt.lib?
Oct 02 2020
On Friday, 2 October 2020 at 07:34:03 UTC, WhatMeWorry wrote:On Thursday, 1 October 2020 at 21:56:46 UTC, Ferhat Kurtulmuş wrote:Here are the steps I used with success: in a VCx64 cmd -> set PATH=%PATH%;D:\dlang\dmd.2.094.0.windows\dmd2\windows\bin64 ------------------------ module user; import std.stdio; import mydll; // Yes, I imported the dll here //export { int myAddSeven(int a, int b); } void main() { int total = mydll.myAddSeven(2, 3); writeln(total); } ------------------------- module mydll; export extern(D) { int myAddSeven(int a, int b) { return a+b+7; } /* <-- function body */ } --------------------------- dmd -m64 -ofmydll.dll mydll.d -L/NOENTRY -L/DLL dmd -m64 user.d mydll.libOn Thursday, 1 October 2020 at 21:35:42 UTC, WhatMeWorry wrote:Yes, I've been doing that.On Thursday, 1 October 2020 at 20:28:58 UTC, kinke wrote:1) try running your commands in Visual Studio Native x64 CMD.[...]Thanks all. I've gotten it to work with:[...][...][...]total = 12 [...]2) try link with msvcrt.libThe only msvcrt.lib I can find on my Windows 10 machine is: "C:\Windows Kits\10\Lib\10.0.19041.0\um\x64\ntstc_msvcrt.lib" Also on Microsoft's docs https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-f atures?view=vs-2019 it talks about a ucrt.lib?
Oct 02 2020
On Friday, 2 October 2020 at 08:07:33 UTC, Ferhat Kurtulmuş wrote:On Friday, 2 October 2020 at 07:34:03 UTC, WhatMeWorry wrote:Did you create a D-partition just for D. ProOn Thursday, 1 October 2020 at 21:56:46 UTC, Ferhat Kurtulmuş wrote:Here are the steps I used with success: in a VCx64 cmd -> set PATH=%PATH%;D:\dlang\dmd.2.094.0.windows\dmd2\windows\bin64On Thursday, 1 October 2020 at 21:35:42 UTC, WhatMeWorry wrote:Yes, I've been doing that.[...]1) try running your commands in Visual Studio Native x64 CMD.2) try link with msvcrt.libThe only msvcrt.lib I can find on my Windows 10 machine is: "C:\Windows Kits\10\Lib\10.0.19041.0\um\x64\ntstc_msvcrt.lib" Also on Microsoft's docs https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-f atures?view=vs-2019 it talks about a ucrt.lib?
Oct 02 2020
On Friday, 2 October 2020 at 08:33:25 UTC, Imperatorn wrote:On Friday, 2 October 2020 at 08:07:33 UTC, Ferhat Kurtulmuş wrote:Haha. Yes my c compiler is also located at c:\cOn Friday, 2 October 2020 at 07:34:03 UTC, WhatMeWorry wrote:Did you create a D-partition just for D. ProOn Thursday, 1 October 2020 at 21:56:46 UTC, Ferhat Kurtulmuş wrote:Here are the steps I used with success: in a VCx64 cmd -> set PATH=%PATH%;D:\dlang\dmd.2.094.0.windows\dmd2\windows\bin64[...]Yes, I've been doing that.[...]The only msvcrt.lib I can find on my Windows 10 machine is: "C:\Windows Kits\10\Lib\10.0.19041.0\um\x64\ntstc_msvcrt.lib" Also on Microsoft's docs https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-f atures?view=vs-2019 it talks about a ucrt.lib?
Oct 02 2020
On 02/10/2020 9:33 PM, Imperatorn wrote:Did you create a D-partition just for D. ProYou can mount directories as a drive on Windows. https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/subst
Oct 02 2020
On Tuesday, 29 September 2020 at 21:22:21 UTC, WhatMeWorry wrote:module user; export { int myAddSeven(int a, int b); } [...]As example, DLL: https://github.com/vitalfadeev/dlang-dll
Oct 01 2020