digitalmars.D.learn - How to setup D with SFML? (using bindbc-sfml)
- Ki Rill (9/9) Apr 08 2023 How do I set up a D and SFML project using the `bindbc-sfml`
- Mike Parker (4/14) Apr 08 2023 Not without error messages. The first thing you should do is use
- Salih Dincer (55/58) Apr 08 2023 I installed it on my Linux system without using a loader and with
- Ki Rill (17/34) Apr 09 2023 I forgot about that). Here are the errors that occur on Windows:
- Mike Parker (38/48) Apr 09 2023 I've tried your project out two ways, one that succeeds and one
- Ki Rill (78/99) Apr 11 2023 I tried `bin/libs/` as well as you describe here. It did not work.
- Salih Dincer (22/70) Apr 12 2023 If I add "BindSFML_Static" to the DUB's version directive, I
- Ki Rill (7/25) Apr 13 2023 I tried static. It did not work. Now it gives me this error:
- Salih Dincer (12/17) Apr 13 2023 Since this library is a component of the Microsoft C Runtime
- Ki Rill (3/21) Apr 14 2023 Yay! That worked! Now I have a working example. Though it's
- Salih Dincer (7/9) Apr 14 2023 Good luck, I'm really happy for you...
- Richard (Rikki) Andrew Cattermole (4/4) Apr 11 2023 I have to ask this since nothing else has worked and the dll's on the
- Ki Rill (5/9) Apr 11 2023 I uses the default settings. DUB should compile my project as
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](https://github.com/rillki/d-sfml-project-template) 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?
Apr 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](https://github.com/rillki/d-sfml-project-template) 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.
Apr 08 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: ```java "libs": [ "csfml-audio", "csfml-graphics" ], "subConfigurations": { "bindbc-sfml": "staticBC" }, "versions": [ "SFML_Audio", "SFML_Graphics" ], ``` 5. dub **app.d** ```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
Apr 08 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: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: ```D version(Windows) { import bindbc.loader; setCustomLoaderSearchPath("libs"); // tried using absolute path as well } ``` That is strange...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](https://github.com/rillki/d-sfml-project-template) 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.
Apr 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: ```D 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.
Apr 09 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](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.
Apr 11 2023
On Tuesday, 11 April 2023 at 10:24:09 UTC, Ki Rill wrote: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" ] } ``` 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 -11If 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: ```Json "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
Apr 12 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: ```Json "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 79I 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?
Apr 13 2023
On Friday, 14 April 2023 at 00:28:53 UTC, Ki Rill wrote:``` 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?Since this library is a component of the Microsoft C Runtime (CRT) library, you may need to install this library. To install the CRT library, follow these steps: * Download and install the latest version of Microsoft Visual Studio. * In the Visual Studio installer, install the "C++ Universal CRT" component under "Workloads > Desktop development with C++". * Restart the build and check if the error is resolved. **Source:** https://stackoverflow.com/questions/44763817/link-fatal-error-lnk1104-cannot-open-file-ucrt-lib SDB 79
Apr 13 2023
On Friday, 14 April 2023 at 02:33:18 UTC, Salih Dincer wrote:On Friday, 14 April 2023 at 00:28:53 UTC, Ki Rill wrote:Yay! That worked! Now I have a working example. Though it's strange that it does not work with shared libs.``` 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?Since this library is a component of the Microsoft C Runtime (CRT) library, you may need to install this library. To install the CRT library, follow these steps: * Download and install the latest version of Microsoft Visual Studio. * In the Visual Studio installer, install the "C++ Universal CRT" component under "Workloads > Desktop development with C++". * Restart the build and check if the error is resolved. **Source:** https://stackoverflow.com/questions/44763817/link-fatal-error-lnk1104-cannot-open-file-ucrt-lib SDB 79
Apr 14 2023
On Friday, 14 April 2023 at 12:26:25 UTC, Ki Rill wrote:Yay! That worked! Now I have a working example. Though it's strange that it does not work with shared libs.Good luck, I'm really happy for you... Ki Rill, wait a minute! Actually, i've been very happy for the D community. Because I really appreciate what you've done. You are an idealistic person and please stay that way. We can do more things. SDB 79
Apr 14 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?
Apr 11 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.
Apr 11 2023