www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Visual Studio Linker Problem

reply Jason C. Wells <example example.com> writes:
I am working my way up to building NanoVG per my previous post.

I am able to compile hello world using dmd2. I am running in 
cygwin because I understand bash way better than cmd.exe.

I am unable to compile hello world using ldc2. I am interested in 
ldc because I am interested in compiling to different arch-es and 
I happen to be a FreeBSD guy which uses LLVM by default. I figure 
that what I learn in LDC under windows will be portable for me.

I received this error:

$ ldc2 hello.d
Using Visual C++: C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC
LINK : fatal error LNK1104: cannot open file 'libucrt.lib'
Error: `C:\Windows\system32\cmd.exe /s /c 
"C:\Users\jcw\Documents\Projects\Programming\dlang\ldc2-1.1.0-beta3-win6
-msvc\bin\amd64.bat link.exe"` failed with status: 1104

The file "libucrt.lib" is found in several VS folders.

I am sure that this is some path issue, but I'm not savvy on 
VisualStudio. I read some scary messages about this error in 
other parts of the forum from about a year ago. Hopefully the 
solution is easier than what I read in that thread.

I see mention of a "vcvarsall.bat" file that might set my paths 
correctly, but this file is not found on my system.

I see mention of a VCINSTALLDIR variable which is not set on my 
system.

Regards,
Jason C. Wells
Oct 17 2016
next sibling parent Mike Parker <aldacron gmail.com> writes:
On Tuesday, 18 October 2016 at 05:23:15 UTC, Jason C. Wells wrote:

 $ ldc2 hello.d
 Using Visual C++: C:\Program Files (x86)\Microsoft Visual 
 Studio 14.0\VC
 I see mention of a "vcvarsall.bat" file that might set my paths 
 correctly, but this file is not found on my system.
Are you sure? The path should be: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat I use MSYS2 frequently, but not with D or the Visual Studio tools, so I can't speak to anything specific in that regard. However, in my programs menu in the Visual Studio 2015 folder are several command prompt shortcuts which are preconfigured to set the environment for the VS tools. I suggest you open one of those and see if you can build anything with ldc, then go from there.
Oct 18 2016
prev sibling next sibling parent Mike Parker <aldacron gmail.com> writes:
On Tuesday, 18 October 2016 at 05:23:15 UTC, Jason C. Wells wrote:

 The file "libucrt.lib" is found in several VS folders.

 I am sure that this is some path issue, but I'm not savvy on 
 VisualStudio. I read some scary messages about this error in 
 other parts of the forum from about a year ago. Hopefully the 
 solution is easier than what I read in that thread.
And I should mention that the old issue you're talking about was a side effect of a big change in Visual Studio 2015 over previous versions that DMD was unable to handle. Once DMD got caught up, the problem went away. I don't know that LDC was ever affected by it.
Oct 18 2016
prev sibling next sibling parent Johan Engelen <j j.nl> writes:
On Tuesday, 18 October 2016 at 05:23:15 UTC, Jason C. Wells wrote:
 I am working my way up to building NanoVG per my previous post.

 I am able to compile hello world using dmd2. I am running in 
 cygwin because I understand bash way better than cmd.exe.
Does `ldc2 hello.d` also fail in cmd.exe?
 [snip

 I see mention of a "vcvarsall.bat" file that might set my paths 
 correctly, but this file is not found on my system.
LDC's amd64.bat script should complain about it not being able to find "vcvarsall.bat".
 I see mention of a VCINSTALLDIR variable which is not set on my 
 system.
That's expected, that variable is set by one of VS's batch scripts. -Johan
Oct 18 2016
prev sibling next sibling parent kink <noone nowhere.com> writes:
On Tuesday, 18 October 2016 at 05:23:15 UTC, Jason C. Wells wrote:
 I am able to compile hello world using dmd2. I am running in 
 cygwin because I understand bash way better than cmd.exe.
I bet it works if you invoke LDC outside bash. bash may tamper with environment variables, I've had a similiar issue with a bash shipped with PortableGit for Windows (C:\... => /C/...).
Oct 18 2016
prev sibling parent reply Jason C. Wells <example example.com> writes:
C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\vcvarsall.bat did in fact exist. My search for the file 
must have been errant.

ldc2.exe hello.d also failed in cmd.exe.

I took Mike's advice to run cmd.exe from one of the environments 
provided in the VS start menu. I tried to compile hello world and 
failed with the same error.

I then ran 'set > environment.txt'. The value of LIB included the 
path:

C:\Program Files (x86)\Windows Kits\10\lib\10.0.14393.0\ucrt\x64

which should have been:

C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10150.0\ucrt\x64.

I reset environment variable LIB to include the path to 
libucrt.lib. I was able to compile hello.d

Thanks all. Your advice set me on the right path.

Regards,
Jason C. Wells
Oct 18 2016
parent reply Johan Engelen <j j.nl> writes:
On Tuesday, 18 October 2016 at 17:29:34 UTC, Jason C. Wells wrote:
 C:\Program Files (x86)\Microsoft Visual Studio 
 14.0\VC\vcvarsall.bat did in fact exist. My search for the file 
 must have been errant.

 ldc2.exe hello.d also failed in cmd.exe.

 I took Mike's advice to run cmd.exe from one of the 
 environments provided in the VS start menu. I tried to compile 
 hello world and failed with the same error.

 I then ran 'set > environment.txt'. The value of LIB included 
 the path:

 C:\Program Files (x86)\Windows Kits\10\lib\10.0.14393.0\ucrt\x64

 which should have been:

 C:\Program Files (x86)\Windows 
 Kits\10\Lib\10.0.10150.0\ucrt\x64.

 I reset environment variable LIB to include the path to 
 libucrt.lib. I was able to compile hello.d

 Thanks all. Your advice set me on the right path.
So this was a VS installation issue? (Visual Studio set the LIB path wrong?)
Oct 18 2016
parent reply Jason C. Wells <example example.com> writes:
On Tuesday, 18 October 2016 at 18:09:11 UTC, Johan Engelen wrote:

 So this was a VS installation issue? (Visual Studio set the LIB 
 path wrong?)
I'm not sure where LIB was set.
Oct 18 2016
parent Kagamin <spam here.lot> writes:
On Tuesday, 18 October 2016 at 18:18:16 UTC, Jason C. Wells wrote:
 I'm not sure where LIB was set.
At least in vs2013 it's taken from registry somewhere HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v8.1 (maybe v10 in your case).
Oct 19 2016