Thread overview
Cannot link vibe.d sample / optlink error
Apr 08, 2019
Michal Minich
Apr 08, 2019
Radu
Apr 09, 2019
Michal Minich
Apr 09, 2019
Seb
April 08, 2019
I used dmd 2.085.0 and 2.085.1 on Win 10

I followed sample at
https://vibed.org/blog/posts/a-scalable-chat-room-service-in-d

Just the beginning, where you you should compile hello word web app.

command line: "dub"

compilation finishes ok. then it prints "Linking..." and I get window message box:

---------------------------
Unexpected OPTLINK Termination at EIP=0040F60A
---------------------------
EAX=073D0000 EBX=00438C70 ECX=00000B2F EDX=0000038A
ESI=0000008F EDI=073D1344 EBP=0019FF28 ESP=0019FEE0
First=00402000
---------------------------
OK
---------------------------

I also tried clean build with dflags -m32mscoff. But then I get another kind of errors.

Any help moving forward is appreciated.
April 08, 2019
On Monday, 8 April 2019 at 13:42:31 UTC, Michal Minich wrote:
> I used dmd 2.085.0 and 2.085.1 on Win 10
>
> I followed sample at
> https://vibed.org/blog/posts/a-scalable-chat-room-service-in-d
>
> Just the beginning, where you you should compile hello word web app.
>
> command line: "dub"
>
> compilation finishes ok. then it prints "Linking..." and I get window message box:
>
> ---------------------------
> Unexpected OPTLINK Termination at EIP=0040F60A
> ---------------------------
> EAX=073D0000 EBX=00438C70 ECX=00000B2F EDX=0000038A
> ESI=0000008F EDI=073D1344 EBP=0019FF28 ESP=0019FEE0
> First=00402000
> ---------------------------
> OK
> ---------------------------
>
> I also tried clean build with dflags -m32mscoff. But then I get another kind of errors.
>
> Any help moving forward is appreciated.

Hi there,
Compiling with 2.085.1 on Windows 10 works with `dub --arch=x86_mscoff`
LDC 1.15.0 works for x86/x86_64. Tested also on a fresh VMWare instance running Windows 7.

You can try running it with `dub --arch=x86_mscoff --verbose` in order to get more diagnostic messages for build errors.

Make sure you have "Visual C++ Redistributable for Visual Studio 2015" installed, it is required to be able to run the produced executable, if you don't build it using the Visual Studio command line. The reason is that both DMD and LDC will use the MinGW `.lib` files, which require a dynamic linked C runtime (static linking is permitted only with Visual Studio)
April 09, 2019
On Monday, 8 April 2019 at 14:49:02 UTC, Radu wrote:

> Hi there,
> Compiling with 2.085.1 on Windows 10 works with `dub --arch=x86_mscoff`
> LDC 1.15.0 works for x86/x86_64. Tested also on a fresh VMWare instance running Windows 7.
>
> You can try running it with `dub --arch=x86_mscoff --verbose` in order to get more diagnostic messages for build errors.
>
> Make sure you have "Visual C++ Redistributable for Visual Studio 2015" installed, it is required to be able to run the produced executable, if you don't build it using the Visual Studio command line. The reason is that both DMD and LDC will use the MinGW `.lib` files, which require a dynamic linked C runtime (static linking is permitted only with Visual Studio)

Thank you Radu!

Your answer helped and hello word is now running :)

After using --verbose I found that I do not have libcmt.lib on my computer at all. Though I have Visual Studio 2019 installed, it is for C#. Looks like when you have VS 2019, then classical redistributable packages are not supported any more. After a bit of experimenting I found adding "MSVC v142 - VS2019 C== x86/x85 build tools (v13.20" from VS installer installed the libcmt.lib. After running dub with --arch=x86_mscoff from VS command line it worked.
April 09, 2019
On Tuesday, 9 April 2019 at 06:50:36 UTC, Michal Minich wrote:
> On Monday, 8 April 2019 at 14:49:02 UTC, Radu wrote:
>
>> [...]
>
> Thank you Radu!
>
> Your answer helped and hello word is now running :)
>
> After using --verbose I found that I do not have libcmt.lib on my computer at all. Though I have Visual Studio 2019 installed, it is for C#. Looks like when you have VS 2019, then classical redistributable packages are not supported any more. After a bit of experimenting I found adding "MSVC v142 - VS2019 C== x86/x85 build tools (v13.20" from VS installer installed the libcmt.lib. After running dub with --arch=x86_mscoff from VS command line it worked.

See also this related issue with quite some discussion on the topic:

https://issues.dlang.org/show_bug.cgi?id=19760