Thread overview
DMD Windows 64bit target - how to setup the environment?
Dec 25
realhet
Dec 25
realhet
Dec 29
realhet
December 25
Hello,

I'm very well satisfied with the DMD 32bit compiler and the OptLink linker on Windows. I even made an incremental builder to it, and I can see the running program in 1 second.
Lately I sadly noticed, that the OptLink works only for 32bit target, and I need to go to 64bit if I want to have access to the SIMD instructions on vector operations.
So this is what I've tried so far:

- Installed visual C++ 2010.
- Installed Windows SDK 7.1 (don't know why, 'though)

  -> Error: dmd cant find "\bin\link.exe"
- Added environment variable: set VCINSTALLDIR=c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC

  -> Error: Can't load mspdb100.dll
- Added set PATH=%PATH%;c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE

  -> Error: LNK1104: cannot open file 'libcmt.lib'
- copied it to c:\D\dmd2\windows\lib64 (yes, I really desperately want it to work lol)

  -> Error: LNK1104: OLDNAMES.lib, shell32.lib
- copied these too

And finally got the error:
  -> libcmt.lib(fdopen.obj) : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'

So I've searched through the whole C drive and this 32bit one was the only libcmt.lib.
The linker is located at: "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe"
There is no amd64 folder near to it at all.

Obviously I'm doing something wrong because a trivial task like changing target to 64bit can't be so complicated. Please help and tell me how to do it properly!

Thanks in advance!


December 25
Now I have my first DMD 64bit windows console app running. (And I'm already afraid of the upcoming windowed application haha)

After further fiddling I installed the >>>Visual Cpp tools 2015<<< package that contains a linker with x64 stuff in it (along with several GB of bloatware).

contents of test64bit.d: import std.stdio; void main(){writeln("Hello 64");}

compiling:
>dmd test64bit.d -c -op -allinst -vcolumns -m64

linking:
>"c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\link.exe"
  /MACHINE:X64
  /SUBSYSTEM:CONSOLE
  test64bit.obj
  /LIBPATH:c:\D\dmd2\windows\lib64
  /LIBPATH:"c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\amd64"
  /LIBPATH:"c:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64"
  /LIBPATH:"c:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x64"
  legacy_stdio_definitions.lib

(note: legacy_stdio_definitions.lib contains sprintf and sscanf)
December 25
On Monday, 25 December 2017 at 16:35:26 UTC, realhet wrote:
> Now I have my first DMD 64bit windows console app running. (And I'm already afraid of the upcoming windowed application haha)


My recommendation for getting setup on Windows with D is as follows:

1) Install the latest visual studio community version: https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=Community&rel=15
2) Install dmd through the windows installer: https://dlang.org/download.html , exe option under windows. This will correctly configure dmd to use the visual studio install from above. From here on dmd will be able to compiler with -m64 and -m32mscoff from the command line.
3) Install VisualD from http://rainers.github.io/visuald/visuald/StartPage.html
4) Create a D project in visual studio and start programming. Compile and debug as usual in Visual Studio.


For you command line compilation. Why are you passing -c to the compiler? The idea behind D is that you pass all modules at the same time to the compiler. This allows the compiler to reuse template instances across modules and in general compilation with D is fast enough to be able to recompile everything each time you make changes. No need for a build system. A single batch file with one command in it is usually enough. There is no need to call the linker manually. Dmd will do this for you. Just call dmd like this:

dmd -m64 source1.d source2.d source3.d -ofoutput.exe

and thats it. You can add additional options like -O -inline -noboundscheck -g -debug -relase. Those are the most commoly used options.

Kind Regards
Benjamin Thaut



December 25
On Monday, 25 December 2017 at 10:57:46 UTC, realhet wrote:
> Hello,
>
> I'm very well satisfied with the DMD 32bit compiler and the OptLink linker on Windows. I even made an incremental builder to it, and I can see the running program in 1 second.
> Lately I sadly noticed, that the OptLink works only for 32bit target, and I need to go to 64bit if I want to have access to the SIMD instructions on vector operations.
> So this is what I've tried so far:
>
> - Installed visual C++ 2010.
> - Installed Windows SDK 7.1 (don't know why, 'though)
>
>   -> Error: dmd cant find "\bin\link.exe"
> - Added environment variable: set VCINSTALLDIR=c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC
>
>   -> Error: Can't load mspdb100.dll
> - Added set PATH=%PATH%;c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
>
>   -> Error: LNK1104: cannot open file 'libcmt.lib'
> - copied it to c:\D\dmd2\windows\lib64 (yes, I really desperately want it to work lol)
>
>   -> Error: LNK1104: OLDNAMES.lib, shell32.lib
> - copied these too
>
> And finally got the error:
>   -> libcmt.lib(fdopen.obj) : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'
>
> So I've searched through the whole C drive and this 32bit one was the only libcmt.lib.
> The linker is located at: "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe"
> There is no amd64 folder near to it at all.
>
> Obviously I'm doing something wrong because a trivial task like changing target to 64bit can't be so complicated. Please help and tell me how to do it properly!
>
> Thanks in advance!

If it is ok for you to use LDC (win 64) then there is one major advantage using it over DMD.

The MS visual studio / build tool comes with a handy batch script vcvarsall. After calling it with the 64 parameter several environment variables are set which are directly recognized by LDC.

Just call the vcvarsall batch and LDC will work out of the box.

I created an issue for DMD to enable this feature too.

Kind regards
Andre

December 29
Thank You for fast help! I just reply late because I wanted to try out many things.

With Benjamin's list it was indeed easy to set up the environment.
I also installed LDC and it worked without problems too.
Made some tests about sse vectorization and it turned out that I'm in love with LDC now :D
( https://realhet.wordpress.com/2017/12/29/my-first-impressions-of-64-bit-dlang-compilers/ )

The next thing I wanna test is compiling speed.
As you said, DMD is fast enought to let it just compile all the project in one run, because it reuses a lot of data it discovered through the compiling process.
However I had a lot of experiences with Delphi which is a really fast one (at least on 32bits, without sse vectorization), and on top of that is uses incremental compilation. Later I got to Qt+MSVC, and noticed that my 40K LOC not-so-big project takes 40 seconds to compile and another 10 to launch in the debugger. At the time when the program started, I already forgot why I started it to debug, lol. So that's why I was happy to find D, an elegant language that compiles fast, (not as fast as Delphi, 'though, but it is really comparable to it). So for development, I made a small incremental build manager thingie: It launches a DMD for each of the modules, that aren't in its cache. For a 6K LOC, 220KB project i was able to test, it works well: When I modify a only high level module, it only takes 3 seconds to launch, not 7 while I build it once with DMD. When the object cache is empty, it takes 6 seconds on all 8 cores, but it has to be done only once. On Delphi I had usually 0.5sec launch times when I changed only a few units, so if I have to choose 7 secs of 3 secs, then it's not even a question.

Anyways,
Thank You for help again!