On Sunday, 9 April 2023 at 14:20:30 UTC, Mike Parker wrote:
I've tried your project out two ways, one that succeeds and one that fails. I'm guessing you've put your 'libs' directory is 'bin/libs'. Am I right? If so, then the following should help you.

Well, `bin/` and `libs/` are in the same directory.

When dub runs the exectuable, it sets the current working directory to the project's root directory by default. `setCustomLoaderPath` passes whatever you give it directly to the system API unmodified. You've passed a relative path. By default, the system API associates relative paths with the current working directory.

So given a project root directory of `$ROOT`, and your executable in `$ROOT/bin`, the system is looking for the libraries in `$ROOT/libs` and *not* in `$ROOT/bin/libs`. If the libs are in the former, everything loads. If they're in the latter, then it's going to fail.

If you cd into `bin` and run the executable manually, then libs in `$ROOT/bin/libs` will load, as your current working directory is `bin`.

The quick fix for this is to add `"workingDirectory" : "bin"` to your dub.json. Then your relative paths will be relative to `$ROOT/bin/`.


I tried `bin/libs/` as well as you describe here. It did not work.

---

Actually, it is quite strange that it fails to load the [CSFML](https://www.sfml-dev.org/download/csfml/) library dlls in `libs/` (I download CSFML2.5) since that is what I do with [GLFW/OpenGL](https://github.com/rillki/d-glfw-opengl-project-template) example as well for Windows 10.

**Even this fails: `loadSFMLGraphics("libs/csfml-graphics.dll")`**

I have the following structure:
```
- bin/
- libs/
- source/
- dub.json
- dub.selections.json
```

My `dub.json`:
```Json
{
        "authors": [
                "rillki"
        ],
        "copyright": "Copyright © 2023, rillki",
        "dependencies": {
                "bindbc-sfml": "~>1.0.2"
        },
        "description": "D/SFML project template",
        "license": "BSL",
        "name": "d-sfml-project-template",
        "targetPath": "bin",
        "versions": [
                "SFML_Audio",
                "SFML_Graphics",
                "SFML_Network",
                "SFML_System",
                "SFML_Window",
                "SFML_250"
        ]
}
```

My `source/app.d`:
```d
module app;

import std.stdio: writeln;
import bindbc.sfml;

void main() {
    version(Windows) {
        import bindbc.loader;
        setCustomLoaderSearchPath("libs");
    }

    // attempt at loading sfml
    if(!loadSFML()) {
        writeln("Failed to load SFML library!");
        return;
    }

    // window dimensions
    enum width = 720;
    enum height = 480;
    enum title = "D/SFML project";

    // create window
auto window = sfWindow_create(sfVideoMode(width, height), title.toStringz, sfWindowStyle.sfDefaultStyle, null);
    scope(exit) { sfWindow_destroy(window); }

    while(sfWindow_isOpen(window)) {
        // process events
        sfEvent event;
        while(sfWindow_pollEvent(window, &event)) {
            if(event.type == sfEventType.sfEvtClosed) {
                sfWindow_close(window);
            }
        }

        // ...
    }
}

```

I will try to make it work... Meanwhile, if someones spots what I am doing wrong, please reply to this post.
  • How to setup D w... Ki Rill via Digitalmars-d-learn
    • Re: How to ... Mike Parker via Digitalmars-d-learn
      • Re: How... Salih Dincer via Digitalmars-d-learn
      • Re: How... Ki Rill via Digitalmars-d-learn
        • Re:... Mike Parker via Digitalmars-d-learn
          • ... Ki Rill via Digitalmars-d-learn
            • ... Salih Dincer via Digitalmars-d-learn
              • ... Ki Rill via Digitalmars-d-learn
                • ... Salih Dincer via Digitalmars-d-learn
                • ... Ki Rill via Digitalmars-d-learn
                • ... Salih Dincer via Digitalmars-d-learn
    • Re: How to ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn

Reply via email to