www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - Linking with a c library on windows with ldc

reply maik klein <maikklein googlemail.com> writes:
I just wanted to build my project on windows, but it turned out 
to be much harder than I thought. In DMD there is some legacy 
stuff with 32bit apps but I mostly ignored it because I want to 
ouput 64 bit binaries anways. The problem is dmd always return an 
ICE if want to generate a 64bit binary.

So I thought I would give ldc a try.

The first problem was with dub, as currently it still outputs a 
'.a' lib on windows, so I had to fix that.

I am currently linking with glfw on linux like this

dependency "derelict-glfw3" version="~>2.0.0"
subConfiguration "derelict-glfw3" "derelict-glfw3-static"
sourceFiles "deps/linux64/libglfw3.a"
libs "Xi" "pthread" "X11" "Xxf86vm" "Xrandr" "pthread" "GL" "GLU" 
"Xinerama" "Xcursor"

This is how I did it on windows

dependency "derelict-glfw3" version="~>2.0.0"
subConfiguration "derelict-glfw3" "derelict-glfw3-static"
sourceFiles "deps/win64/libglfw3.lib"
libs "opengl32"

I just installed vs2013 and vcredist2013 and vsredist2015 on 
windows 7.

First I got a linker error that it couldn't find opengl32, so I 
temporarily removed it.

Then I got a linker error with legacy_stdio. I made a quick 
google search and I found an issue for ldc. Apparently I had to 
remove a line from  ldc2.ini to make it work with vs2013.

But there was nothing related to legacy_stdio inside this .ini so 
I removed vs2013 and installed vs2015.

But I get an error with vs2015 for both dmd and ldc.

So my question:

What do I need to install? Have I done anything wrong? Are there 
any docs that can help me?
Apr 01 2016
parent reply Kagamin <spam here.lot> writes:
The error message and other diagnostic means can help you.
Apr 01 2016
parent reply maik klein <maikklein googlemail.com> writes:
On Friday, 1 April 2016 at 12:52:45 UTC, Kagamin wrote:
 The error message and other diagnostic means can help you.
There is no error message other then the linking has failed. Which diagnostic tools are available?
Apr 01 2016
parent reply ZombineDev <petar.p.kirov gmail.com> writes:
On Friday, 1 April 2016 at 14:13:05 UTC, maik klein wrote:
 On Friday, 1 April 2016 at 12:52:45 UTC, Kagamin wrote:
 The error message and other diagnostic means can help you.
There is no error message other then the linking has failed. Which diagnostic tools are available?
What is the exact linking error?
Apr 01 2016
parent reply maik klein <maikklein googlemail.com> writes:
On Friday, 1 April 2016 at 14:17:41 UTC, ZombineDev wrote:
 On Friday, 1 April 2016 at 14:13:05 UTC, maik klein wrote:
 On Friday, 1 April 2016 at 12:52:45 UTC, Kagamin wrote:
 The error message and other diagnostic means can help you.
There is no error message other then the linking has failed. Which diagnostic tools are available?
What is the exact linking error?
I currently have Vs2015 installed Error: `C:\Windows\system32\cmd.exe /s /c "C:\Users\maik\Downloads\ldc2-0.17.1-w in64-msvc\bin\amd64.bat lib.exe"` failed with status: 9009 ldc2 failed with exit code 9009. With Vs2013 the linking error was something along the lines "Error: Failed to link with legacy_stdio". I am on a fresh install of Windows 7 but I will reinstall Windows 7 tomorrow when my new SSD arrives. I think only Vs2013 works with ldc?
Apr 01 2016
parent reply Johan Engelen <j j.nl> writes:
On Friday, 1 April 2016 at 14:26:23 UTC, maik klein wrote:
 I currently have Vs2015 installed

 Error: `C:\Windows\system32\cmd.exe /s /c 
 "C:\Users\maik\Downloads\ldc2-0.17.1-w
 in64-msvc\bin\amd64.bat lib.exe"` failed with status: 9009
 ldc2 failed with exit code 9009.
This doesn't look like a linking error to me. Can LDC create obj files? (use the "-c" cmdline option)
  I think only Vs2013 works with ldc?
We encourage using VS2015. -Johan
Apr 01 2016
parent reply maik klein <maikklein googlemail.com> writes:
On Friday, 1 April 2016 at 14:36:27 UTC, Johan Engelen wrote:
 On Friday, 1 April 2016 at 14:26:23 UTC, maik klein wrote:
 I currently have Vs2015 installed

 Error: `C:\Windows\system32\cmd.exe /s /c 
 "C:\Users\maik\Downloads\ldc2-0.17.1-w
 in64-msvc\bin\amd64.bat lib.exe"` failed with status: 9009
 ldc2 failed with exit code 9009.
This doesn't look like a linking error to me. Can LDC create obj files? (use the "-c" cmdline option)
  I think only Vs2013 works with ldc?
We encourage using VS2015. -Johan
With Vs2015: I can output .obj files with c //test.d import std.stdio; void main(){ writeln("test"); } ldc2 test.d => same error as above ldc2 test.d -c works
Apr 01 2016
parent reply maik klein <maikklein googlemail.com> writes:
On Friday, 1 April 2016 at 14:48:17 UTC, maik klein wrote:
 On Friday, 1 April 2016 at 14:36:27 UTC, Johan Engelen wrote:
 On Friday, 1 April 2016 at 14:26:23 UTC, maik klein wrote:
 I currently have Vs2015 installed

 Error: `C:\Windows\system32\cmd.exe /s /c 
 "C:\Users\maik\Downloads\ldc2-0.17.1-w
 in64-msvc\bin\amd64.bat lib.exe"` failed with status: 9009
 ldc2 failed with exit code 9009.
This doesn't look like a linking error to me. Can LDC create obj files? (use the "-c" cmdline option)
  I think only Vs2013 works with ldc?
We encourage using VS2015. -Johan
With Vs2015: I can output .obj files with c //test.d import std.stdio; void main(){ writeln("test"); } ldc2 test.d => same error as above ldc2 test.d -c works
Actually the build error is different if I don't use dub ldc2 test.d Using Visual Studio: C:\Program Files (x86)\Microsoft Visual Studio 14.0\ WARNING: could not find VC\vcvarsall.bat link: extra operand '/OPT:REF' Try 'link --help' for more information. Error: `C:\Windows\system32\cmd.exe /s /c "C:\Users\maik\Downloads\ldc2-0.17.1-w in64-msvc\bin\amd64.bat link.exe"` failed with status: 1 So it seems that ldc just doesn't see vcvarsall.bat. I am just not sure where to get it, it doesn't seem to be bundled with visual studio 2015.
Apr 01 2016
parent reply Kai Nacke <kai redstar.de> writes:
On Friday, 1 April 2016 at 15:14:32 UTC, maik klein wrote:
 On Friday, 1 April 2016 at 14:48:17 UTC, maik klein wrote:
 On Friday, 1 April 2016 at 14:36:27 UTC, Johan Engelen wrote:
 On Friday, 1 April 2016 at 14:26:23 UTC, maik klein wrote:
 I currently have Vs2015 installed

 Error: `C:\Windows\system32\cmd.exe /s /c 
 "C:\Users\maik\Downloads\ldc2-0.17.1-w
 in64-msvc\bin\amd64.bat lib.exe"` failed with status: 9009
 ldc2 failed with exit code 9009.
This doesn't look like a linking error to me. Can LDC create obj files? (use the "-c" cmdline option)
  I think only Vs2013 works with ldc?
We encourage using VS2015. -Johan
With Vs2015: I can output .obj files with c //test.d import std.stdio; void main(){ writeln("test"); } ldc2 test.d => same error as above ldc2 test.d -c works
Actually the build error is different if I don't use dub ldc2 test.d Using Visual Studio: C:\Program Files (x86)\Microsoft Visual Studio 14.0\ WARNING: could not find VC\vcvarsall.bat link: extra operand '/OPT:REF' Try 'link --help' for more information. Error: `C:\Windows\system32\cmd.exe /s /c "C:\Users\maik\Downloads\ldc2-0.17.1-w in64-msvc\bin\amd64.bat link.exe"` failed with status: 1 So it seems that ldc just doesn't see vcvarsall.bat. I am just not sure where to get it, it doesn't seem to be bundled with visual studio 2015.
Hi Maik! ldc is built with VS2015 and this is also the recommended VS version. You can use VS2013 but this requires manual work and is not really tested by the LDC team. vcvarsall.bat is part of VS2015. It is located in folder "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC". If you use the "VS2015 x64 Native Tools Command Prompt" then the path is automatically set and the file should be found by ldc. It looks like your PATH variable is messed. Can you link a "hello world" with cl on the command line? Which link.exe is used if the VS path are not set? Could it be that the DMD linker is still in your path? If yes then you should remove it from your path. Regards, Kai
Apr 01 2016
parent reply maik klein <maikklein googlemail.com> writes:
On Friday, 1 April 2016 at 15:47:42 UTC, Kai Nacke wrote:
 On Friday, 1 April 2016 at 15:14:32 UTC, maik klein wrote:
 [...]
Hi Maik! ldc is built with VS2015 and this is also the recommended VS version. You can use VS2013 but this requires manual work and is not really tested by the LDC team. vcvarsall.bat is part of VS2015. It is located in folder "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC". If you use the "VS2015 x64 Native Tools Command Prompt" then the path is automatically set and the file should be found by ldc. It looks like your PATH variable is messed. Can you link a "hello world" with cl on the command line? Which link.exe is used if the VS path are not set? Could it be that the DMD linker is still in your path? If yes then you should remove it from your path. Regards, Kai
It seems that for some reason I didn't install the common c++ extension for VS2015. Oh my god it finally builds and links, I can't believe it. LDC is now my default compiler, keep up the good work and thanks for the help.
Apr 01 2016
parent reply MrSmith <mrsmith33 yandex.ru> writes:
On Friday, 1 April 2016 at 16:28:53 UTC, maik klein wrote:
 On Friday, 1 April 2016 at 15:47:42 UTC, Kai Nacke wrote:
 On Friday, 1 April 2016 at 15:14:32 UTC, maik klein wrote:
 [...]
Oh my god it finally builds and links, I can't believe it. LDC is now my default compiler, keep up the good work and thanks for the help.
Can you please list what have you done to get it working? I have same issues as you.
Apr 07 2016
parent reply maik klein <maikklein googlemail.com> writes:
On Thursday, 7 April 2016 at 16:20:07 UTC, MrSmith wrote:
 On Friday, 1 April 2016 at 16:28:53 UTC, maik klein wrote:
 On Friday, 1 April 2016 at 15:47:42 UTC, Kai Nacke wrote:
 On Friday, 1 April 2016 at 15:14:32 UTC, maik klein wrote:
 [...]
Oh my god it finally builds and links, I can't believe it. LDC is now my default compiler, keep up the good work and thanks for the help.
Can you please list what have you done to get it working? I have same issues as you.
Just click the vs2015 installer again and install "common c++ extension". It is under "C++". I think it is not installed by default.
Apr 07 2016
parent reply MrSmith <mrsmith33 yandex.ru> writes:
On Thursday, 7 April 2016 at 18:38:18 UTC, maik klein wrote:
 Just click the vs2015 installer again and install "common c++ 
 extension". It is under "C++".

 I think it is not installed by default.
I can see only 'Common Tools for Visul C++ 2015'. And it is already installed. Does it work for you with dub and links with C static libs?
Apr 07 2016
parent reply kink <noone nowhere.com> writes:
On Thursday, 7 April 2016 at 22:12:57 UTC, MrSmith wrote:
 I can see only 'Common Tools for Visul C++ 2015'. And it is 
 already installed.
That's it. So what's your error when invoking ldc2 directly? If that works, it's a dub issue. We keep on getting dub bug reports here at LDC, so please report the bugs there if it's only dub related.
Apr 08 2016
parent MrSmith <mrsmith33 yandex.ru> writes:
On Friday, 8 April 2016 at 13:40:25 UTC, kink wrote:
 On Thursday, 7 April 2016 at 22:12:57 UTC, MrSmith wrote:
 I can see only 'Common Tools for Visul C++ 2015'. And it is 
 already installed.
That's it. So what's your error when invoking ldc2 directly? If that works, it's a dub issue. We keep on getting dub bug reports here at LDC, so please report the bugs there if it's only dub related.
Here is it: Using Visual Studio: C:\Program Files (x86)\Microsoft Visual Studio 14.0\ libvcruntime.lib(telemetry.obj) : error LNK2005: __telemetry_main_invoke_trigger already defined in vcruntime.lib(VCRUNTIME140.dll) libvcruntime.lib(telemetry.obj) : error LNK2005: __telemetry_main_return_trigger already defined in vcruntime.lib(VCRUNTIME140.dll) Creating library .dub\build\server-debug-windows-x86_64-ldc_0-222E54A7458436A7C409135 04314236\server.lib and object .dub\build\server-debug-windows-x86_64-ldc_0-222E54A7458436A7C409135304314236\server.exp LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library LINK : warning LNK4098: defaultlib 'vcruntime.lib' conflicts with use of other libs; use /NODEFAULTLIB:library phobos2-ldc.lib(zutil.c.obj) : warning LNK4217: locally defined symbol free imported in function zcfree phobos2-ldc.lib(gzwrite.c.obj) : warning LNK4217: locally defined symbol free imported in function gz_comp phobos2-ldc.lib(gzlib.c.obj) : warning LNK4049: locally defined symbol free imported phobos2-ldc.lib(zutil.c.obj) : warning LNK4217: locally defined symbol malloc imported in function zcalloc phobos2-ldc.lib(gzwrite.c.obj) : warning LNK4217: locally defined symbol malloc imported in function gz_init phobos2-ldc.lib(gzlib.c.obj) : warning LNK4217: locally defined symbol malloc imported in function _snprintf phobos2-ldc.lib(gzwrite.c.obj) : warning LNK4217: locally defined symbol __stdio_common_vsprintf imported in function vsnprintf phobos2-ldc.lib(gzlib.c.obj) : warning LNK4049: locally defined symbol __stdio_common_vsprintf imported phobos2-ldc.lib(gzwrite.c.obj) : warning LNK4217: locally defined symbol _errno imported in function gz_comp druntime-ldc.lib(errno.c.obj) : warning LNK4049: locally defined symbol _errno imported phobos2-ldc.lib(gzwrite.c.obj) : warning LNK4217: locally defined symbol strerror imported in function gz_comp phobos2-ldc.lib(gzlib.c.obj) : warning LNK4217: locally defined symbol _wopen imported in function gz_open phobos2-ldc.lib(gzlib.c.obj) : warning LNK4217: locally defined symbol _lseeki64 imported in function gz_open OLDNAMES.lib(close.obi) : warning LNK4049: locally defined symbol _close imported OLDNAMES.lib(write.obi) : warning LNK4049: locally defined symbol _write imported OLDNAMES.lib(open.obi) : warning LNK4049: locally defined symbol _open imported phobos2-ldc.lib(gzwrite.c.obj) : error LNK2019: unresolved external symbol __imp_close referenced in function gzclose_w OLDNAMES.lib(close.obi) : error LNK2001: unresolved external symbol __imp_close phobos2-ldc.lib(gzwrite.c.obj) : error LNK2019: unresolved external symbol __imp_write referenced in function gz_comp OLDNAMES.lib(write.obi) : error LNK2001: unresolved external symbol __imp_write phobos2-ldc.lib(gzlib.c.obj) : error LNK2019: unresolved external symbol __imp_wcstombs referenced in function gz_open phobos2-ldc.lib(gzlib.c.obj) : error LNK2019: unresolved external symbol __imp_open referenced in function gz_open OLDNAMES.lib(open.obi) : error LNK2001: unresolved external symbol __imp_open .dub\build\server-debug-windows-x86_64-ldc_0-222E54A7458436A7C409135 04314236\server.exe : fatal error LNK1120: 4 unresolved externals Error: `C:\Windows\system32\cmd.exe /s /c "D:\D\ldc2\bin\amd64.bat link.exe"` failed with status: 1120 FAIL .dub\build\server-debug-windows-x86_64-ldc_0-222E54A7458436A7C409135304314236\ server executable ldc2 failed with exit code 1120. Full exception: object.Exception source\dub\compilers\compiler.d(278): ldc2 failed with exit code 1120.
Apr 08 2016