Jump to page: 1 2
Thread overview
DUB: How to link an external library on Windows 10?
Aug 27, 2021
Ki Rill
Aug 27, 2021
Mike Parker
Aug 27, 2021
Ki Rill
Aug 27, 2021
Mike Parker
Aug 27, 2021
Ki Rill
Aug 27, 2021
Ki Rill
Aug 27, 2021
Ki Rill
Aug 27, 2021
Mike Parker
Aug 27, 2021
Ki Rill
Aug 27, 2021
Ki Rill
August 27, 2021

I have a Raylib project on Windows using DUB. I've added raylib-d via dub add. But what I can't figure out is how to tell DUB to link against raylib library.

I have the following project structure:

-> source
---> app.d
-> libraylib.a
-> raylib.dll
-> etc...

I'd like to use either .a or .dll. Do you have any ideas?

August 27, 2021

On Friday, 27 August 2021 at 13:21:04 UTC, Ki Rill wrote:

>

I have a Raylib project on Windows using DUB. I've added raylib-d via dub add. But what I can't figure out is how to tell DUB to link against raylib library.

I have the following project structure:

-> source
---> app.d
-> libraylib.a
-> raylib.dll
-> etc...

I'd like to use either .a or .dll. Do you have any ideas?

raylib.a isn't going to get you anywhere. You'll run into issues mixing MinGW-compiled libraries.

If raylib doesn't ship precompiled VS binaries, then, assuming you have Visual Studio (or the MS Build tools) installed, you should compile Raylib with that same version. Then you'll have a new raylib.dll and a raylib.lib. Add raylib.lib to your dub config via the "libs" directive.

August 27, 2021

On Friday, 27 August 2021 at 13:33:25 UTC, Mike Parker wrote:

>

On Friday, 27 August 2021 at 13:21:04 UTC, Ki Rill wrote:

>

I have a Raylib project on Windows using DUB. I've added raylib-d via dub add. But what I can't figure out is how to tell DUB to link against raylib library.

I have the following project structure:

-> source
---> app.d
-> libraylib.a
-> raylib.dll
-> etc...

I'd like to use either .a or .dll. Do you have any ideas?

raylib.a isn't going to get you anywhere. You'll run into issues mixing MinGW-compiled libraries.

If raylib doesn't ship precompiled VS binaries, then, assuming you have Visual Studio (or the MS Build tools) installed, you should compile Raylib with that same version. Then you'll have a new raylib.dll and a raylib.lib. Add raylib.lib to your dub config via the "libs" directive.

I have downloaded the pre-compiled binaries from the official Raylib repo.

I'm not using Visual Studio. Only dub and a text editor.

August 27, 2021

On 8/27/21 9:21 AM, Ki Rill wrote:

>

I have a Raylib project on Windows using DUB. I've added raylib-d via dub add. But what I can't figure out is how to tell DUB to link against raylib library.

I have the following project structure:

-> source
---> app.d
-> libraylib.a
-> raylib.dll
-> etc...

I'd like to use either .a or .dll. Do you have any ideas?

I spent a lot of time trying to figure this out (someone in discord really wanted to link statically for some reason). I FINALLY got a statically linked exe, but it's not worth the effort. I had to:

  1. update my msvc build tools to match what was used for the official release (alternatively, you can rebuild the raylib library with your tools, otherwise you get cryptic errors like fatal error C1900: Il mismatch between 'P1' version '20210113' and 'P2' version '20190715').
  2. pass in cryptic linker options like /NODEFAULTLIB:libcmt, etc.
  3. Link against extra libraries until the linker errors disappear (google search for missing symbols to see what libraries those symbols are in).

My eventual resulting dub.json looked like (you can guess where I put things):

{
    "name": "rps-explosion",
    "dependencies": {
        "jsoniopipe": "~>0.1.3",
        "enet-d": "~>0.0.1",
        "raylib-d": "~>3.1.0"
    },
    "libs": ["enet", "raylib", "ws2_32", "winmm", "msvcrt", "user32", "gdi32"],
    "lflags": ["/LIBPATH:C:\\dprojects\\enet-1.3.17",
        "/LIBPATH:C:\\dprojects\\raylib-3.7.0_win64_msvc16\\lib", "/NODEFAULTLIB:libcmt", "/NODEFAULTLIB:libvcruntime"]
}

This config also included enet-d so some of the linker options are for that lib.

In the end, I got it to build and run, but I'd highly recommend just linking against the raylibdll.lib and using the dll.

-Steve

August 27, 2021

On Friday, 27 August 2021 at 13:41:56 UTC, Ki Rill wrote:

>

I have downloaded the pre-compiled binaries from the official Raylib repo.

I'm not using Visual Studio. Only dub and a text editor.

But assuming you are on a 64-bit system, the DMD will use Visual Studio's linker if you have it installed. If you don't, it will use the lld linker it ships with. Either way, you need to raylib to be compiled with he same version of the MS Build tools so that you don't have conflicts the the vs runtime.

August 27, 2021

On Friday, 27 August 2021 at 13:54:18 UTC, Steven Schveighoffer wrote:

>

In the end, I got it to build and run, but I'd highly recommend just linking against the raylibdll.lib and using the dll.

-Steve

Steve, thank you! I got it working with raylibdll.lib!

SOLUTION:

  1. dub init

  2. dub add raylib-d

  3. download raylib pre-compiled binaries for Microsoft Visual Studio (msvs)

  4. put raylib.dll and raylibdll.lib into your project's folder (into the same directory, where you have dub.json)

  5. add "libs":["raylibdll"] section into dub.json

Compile and run. It should work.

August 27, 2021

On Friday, 27 August 2021 at 13:54:25 UTC, Mike Parker wrote:

>

But assuming you are on a 64-bit system, the DMD will use Visual Studio's linker if you have it installed. If you don't, it will use the lld linker it ships with. Either way, you need to raylib to be compiled with he same version of the MS Build tools so that you don't have conflicts the the vs runtime.

Indeed, DMD used the lld linker.

August 27, 2021

On Friday, 27 August 2021 at 13:54:18 UTC, Steven Schveighoffer wrote:

>

[...]

How do I tell DUB where to look for raylibdll.lib and raylib.dll? Via lflags section? What if I put them in a different folder instead of the project's directory?

August 27, 2021

On Friday, 27 August 2021 at 14:46:56 UTC, Ki Rill wrote:

>

On Friday, 27 August 2021 at 13:54:18 UTC, Steven Schveighoffer wrote:

>

[...]

How do I tell DUB where to look for raylibdll.lib and raylib.dll? Via lflags section? What if I put them in a different folder instead of the project's directory?

Yes. The path goes in the lflags directive using whatever the linker-specific flag is. I assume for lld it's -Lpath. For MS link it's /LIBPATH:path.

August 27, 2021

On Friday, 27 August 2021 at 14:52:15 UTC, Mike Parker wrote:

>

On Friday, 27 August 2021 at 14:46:56 UTC, Ki Rill wrote:

>

On Friday, 27 August 2021 at 13:54:18 UTC, Steven Schveighoffer wrote:

>

[...]

How do I tell DUB where to look for raylibdll.lib and raylib.dll? Via lflags section? What if I put them in a different folder instead of the project's directory?

Yes. The path goes in the lflags directive using whatever the linker-specific flag is. I assume for lld it's -Lpath. For MS link it's /LIBPATH:path.

I've added lfags:

"lflags": ["/LIBPATH:C:\\Users\\Username\\Desktop\\test\\source\\"]

But now it cannot find the following:

msvcrt120.lib
OLDNAMES.lib
shell32.lib

I think lfags overrides the default search path and I need to add it manually as well. But what is that path on Windows?

« First   ‹ Prev
1 2