Jump to page: 1 2
Thread overview
How to setup D with SFML? (using bindbc-sfml)
Apr 08, 2023
Ki Rill
Apr 08, 2023
Mike Parker
Apr 09, 2023
Salih Dincer
Apr 09, 2023
Ki Rill
Apr 09, 2023
Mike Parker
Apr 11, 2023
Ki Rill
Apr 12, 2023
Salih Dincer
Apr 14, 2023
Ki Rill
Apr 14, 2023
Salih Dincer
Apr 14, 2023
Ki Rill
Apr 14, 2023
Salih Dincer
Apr 12, 2023
Ki Rill
April 08, 2023

How do I set up a D and SFML project using the bindbc-sfml package?

I tried following the instructions, it builds successfully, but fails to load the SFML library at runtime.

In particular, loadSFML, loadSFMLGraphics, loadSFMLXXX fails. Here is link to the repo. I plan to create another how-to video, but I cannot find what's causing it to fail.

Do you have any ideas?

April 08, 2023

On Saturday, 8 April 2023 at 11:31:40 UTC, Ki Rill wrote:

>

How do I set up a D and SFML project using the bindbc-sfml package?

I tried following the instructions, it builds successfully, but fails to load the SFML library at runtime.

In particular, loadSFML, loadSFMLGraphics, loadSFMLXXX fails. Here is link to the repo. I plan to create another how-to video, but I cannot find what's causing it to fail.

Do you have any ideas?

Not without error messages. The first thing you should do is use the error API in bindbc.loader to print them out. That should tell you what the problem is.

April 09, 2023

On Saturday, 8 April 2023 at 23:40:32 UTC, Mike Parker wrote:

>

Not without error messages. The first thing you should do is use the error API in bindbc.loader to print them out. That should tell you what the problem is.

I installed it on my Linux system without using a loader and with static SFML. I just used apt-get and dub. I did the following in order:

  1. sudo apt-get install libsfml-dev libcsfml-dev
  2. dub init dsfml bindbc-sfml
  3. cd dsfml
  4. edit dub.json and add:
  "libs": [
		"csfml-audio",
		"csfml-graphics"
	],
  "subConfigurations": {
		"bindbc-sfml": "staticBC"
	},
  "versions": [
		"SFML_Audio",
		"SFML_Graphics"
	],
  1. dub

app.d

import bindbc.sfml;

void main()
{
  sfContextSettings* settings;
  sfEvent event;

  auto window = sfRenderWindow_create(
    sfVideoMode(750, 500),
    "Japanese Flag",
    sfWindowStyle.sfDefaultStyle,
    settings
  );

  auto flag = sfCircleShape_create();
       flag.sfCircleShape_setRadius(150);
       flag.sfCircleShape_setPosition(sfVector2f(225, 100));
       flag.sfCircleShape_setFillColor(sfRed);

  while(window.sfRenderWindow_isOpen())
  {
    while(window.sfRenderWindow_pollEvent(&event))
    {
      if(event.type == sfEventType.sfEvtClosed)
      {
        window.sfRenderWindow_close();
      }
    }

    window.sfRenderWindow_clear(sfWhite);
    window.sfRenderWindow_drawCircleShape(flag, null);
    window.sfRenderWindow_display();
  }
}

SDB@79

April 09, 2023

On Saturday, 8 April 2023 at 23:40:32 UTC, Mike Parker wrote:

>

On Saturday, 8 April 2023 at 11:31:40 UTC, Ki Rill wrote:

>

How do I set up a D and SFML project using the bindbc-sfml package?

I tried following the instructions, it builds successfully, but fails to load the SFML library at runtime.

In particular, loadSFML, loadSFMLGraphics, loadSFMLXXX fails. Here is link to the repo. I plan to create another how-to video, but I cannot find what's causing it to fail.

Do you have any ideas?

Not without error messages. The first thing you should do is use the error API in bindbc.loader to print them out. That should tell you what the problem is.

I forgot about that). Here are the errors that occur on Windows:

csfml-system.dll, The specified module could not be found.
csfml-audio.dll, The specified module could not be found.
csfml-audio-2.dll, The specified module could not be found.
csfml-audio-2.0.dll, The specified module could not be found.

Why can't it find these libraries? I tell where to look for them:

version(Windows) {
    import bindbc.loader;
    setCustomLoaderSearchPath("libs"); // tried using absolute path as well
}

That is strange...

April 09, 2023

On Sunday, 9 April 2023 at 09:54:26 UTC, Ki Rill wrote:

>

Why can't it find these libraries? I tell where to look for them:

version(Windows) {
    import bindbc.loader;
    setCustomLoaderSearchPath("libs"); // tried using absolute path as well
}

That is strange...

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.

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/.

Bear in mind that when using relative paths like this, any file reading is bound to break if someone runs your executable from outside its directory. You can test this by going into $ROOT from the command line and executing bin/d-sfml-project-template. Then you'll be doing the same thing dub does, i.e., your working directory will be $ROOT.

The way to guarantee your relative paths are always relative to the executable are to either set the current working directory to the executable's path, or to prepend all relative paths with the executable's path before handing them off to the system.

There are two ways you can get the full path to the executable in Phobos/DRuntime: via std.file.thisExePath, or core.runtime.Runtime.args[0]. (The former is failing to compile for me on Windows right now due to a bug in the Phobos Win32 API bindings. I'll look into it.)

Strip the file name from the returned path, then you can use it as required.

April 11, 2023

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 library dlls in libs/ (I download CSFML2.5) since that is what I do with GLFW/OpenGL 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:

{
	"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:

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.

April 11, 2023
I have to ask this since nothing else has worked and the dll's on the site don't depend on a MSVC dll:

What are you compiling your program as? 32bit/64bit x86? ARM?

Which DLL's are you downloading? 32bit, 64bit?

April 12, 2023
On Tuesday, 11 April 2023 at 11:55:50 UTC, Richard (Rikki) Andrew Cattermole wrote:
> I have to ask this since nothing else has worked and the dll's on the site don't depend on a MSVC dll:
>
> What are you compiling your program as? 32bit/64bit x86? ARM?
>
> Which DLL's are you downloading? 32bit, 64bit?

I uses the default settings. DUB should compile my project as 64bit on Windows 10. The bindings I downloaded are also 64bit. The links mentioned in my previous post is what I use.
April 12, 2023

On Tuesday, 11 April 2023 at 10:24:09 UTC, Ki Rill wrote:

>

My dub.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"
	]
}

I will try to make it work... Meanwhile, if someones spots what I am doing wrong, please reply to this post.

If I use your dub.json, my terminal screen says:

>

user@debian:~/Downloads$ cd dsfml
user@debian:~/Downloads/dsfml$ dub
Fetching bindbc-sfml 1.0.2 (getting selected version)
Fetching bindbc-loader 1.0.3 (getting selected version)
Starting Performing "debug" build using /usr/bin/dmd for x86_64.
Building bindbc-loader 1.0.3: building configuration [noBC]
Building bindbc-sfml 1.0.2: building configuration [dynamic]
Building d-sfml-project-template ~master: building configuration [application]
Linking d-sfml-project-template
Running bin/d-sfml-project-template
Error Program exited with code -11

If I add "BindSFML_Static" to the DUB's version directive, I switch to static, which I guess you don't want. But then I also get a bunch of undefined errors:

>

/usr/bin/ld: /home/user/.dub/cache/d-sfml-project-template/~master/build/application-debug-TGcRCxHHanKq_MbfWLee8g/d-sfml-project-template.o: in function _Dmain': /home/user/Downloads/dsfml/source/app.d:11: undefined reference to sfRenderWindow_create'
...
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
Error /usr/bin/dmd failed with exit code 1.

If you wanted static I would add and run libraries easy, like this:

	"libs": [
		"csfml-audio",
		"csfml-graphics"
	],
	"versions": [
		"SFML_Audio",
		"SFML_Graphics",
		"BindSFML_Static",
	]
}

In summary, DUB takes care of everything for us. It should be same in W$...

SDB@79

April 14, 2023

On Wednesday, 12 April 2023 at 10:05:14 UTC, Salih Dincer wrote:

>

On Tuesday, 11 April 2023 at 10:24:09 UTC, Ki Rill wrote:
If you wanted static I would add and run libraries easy, like this:

	"libs": [
		"csfml-audio",
		"csfml-graphics"
	],
	"versions": [
		"SFML_Audio",
		"SFML_Graphics",
		"BindSFML_Static",
	]
}

In summary, DUB takes care of everything for us. It should be same in W$...

SDB@79

I tried static. It did not work. Now it gives me this error:

LINK : fatal error LNK1104: cannot open file 'libucrt.lib'
Error: linker exited with status 1104

Why does it require this library and where can I find it?

« First   ‹ Prev
1 2