windowsddub

Linking with C libraries on Windows with Dub


I am trying to link glfw on windows.

On Linux it was fairly straight forward:

dependency "derelict-glfw3" version="~>2.0.0"
subConfiguration "derelict-glfw3" "derelict-glfw3-static"

sourceFiles "deps/glfw/build/src/libglfw3.a" platform="posix"
libs"Xi" "pthread" "X11" "Xxf86vm" "Xrandr" "pthread" "GL" "GLU" "Xinerama" "Xcursor" platform="posix"

If I try to link with a .dll on windows, dub tells me that Error: unrecognized file extension dll.

dependency "derelict-glfw3" version="~>2.0.0"
subConfiguration "derelict-glfw3" "derelict-glfw3-static"

sourceFiles "deps\\glfw\\build\\src\\Debug\\glfw3.dll" platform="windows"

If I try to link with a .lib, dub tells me that COFF is not supported.

dependency "derelict-glfw3" version="~>2.0.0"
subConfiguration "derelict-glfw3" "derelict-glfw3-static"

sourceFiles "deps\\glfw\\build\\src\\Debug\\glfw3.lib" platform="windows"

GLFW was built with vs2013. What do I have to do differently?


Solution

  • There's three cases here:

    (lol i want this in the list item but markdown sucks. whatever)

    Download this thing to get implib.exe: http://ftp.digitalmars.com/bup.zip and use that to make a .lib from the .dll: implib /s yourdll.lib yourdll.dll and try to link with the new lib. (Add it to the files list like you are already doing)

    If it doesn't work, try the command again, but this time without the /s switch.

    It should work by then.

    Anyway, if you have the Microsoft C++ compiler and linker installed and put that link.exe in your path, dmd -m32mscoff should work using existing .lib files from the dlls.

    TIP: If you used the Windows installer for dmd, open the "D2 64 bit command prompt" from the start menu to get the path set up. It will tell you to use -m64, but you can also use -m32mscoff from that environment and it should work. if everything installed properly.


    In the comments, it sounds like you might also be facing some bugs, I don't know about that, the above is if everything else is working properly.