digitalmars.D.learn - Using bindbc-sdl with D
- idsize (12/12) Mar 11 2023 I started learning D a few weeks ago and am enjoying it so far. I
- Richard (Rikki) Andrew Cattermole (15/25) Mar 11 2023 You don't need to do that, add it as a dependency in your dub package
- Richard (Rikki) Andrew Cattermole (4/9) Mar 11 2023 Ah huh, there is one!
- ryuukk_ (4/13) Mar 11 2023 So this is a dub issue?
- Richard (Rikki) Andrew Cattermole (4/6) Mar 11 2023 Its probably not installed. We don't ship a C toolchain, it uses the
- Andy Valencia (8/11) Mar 26 I tried to use dub several times, and each and every attempt
- idsize (19/22) Mar 11 2023 I've never used a package manager before so the entire process of
- Richard (Rikki) Andrew Cattermole (10/20) Mar 11 2023 Yeah pretty much the same thing in principle.
- Claus D. Volko (62/62) Mar 26 Hi there,
- Mike Parker (13/15) Mar 26 I don't know what's causing your linker errors related to
- ryuukk_ (84/96) Mar 11 2023 Hello, and welcome!
- idsize (2/8) Mar 11 2023 Thanks! It compiled and ran your example successfully.
I started learning D a few weeks ago and am enjoying it so far. I would like to use SDL with D and found bindbc-sdl, but I cannot figure out how to make it work. From my understanding, I'll need to use 'dub fetch bindbc-sdl' to download it, and then run 'dub build bindbc-sdl' to build it, before I can use it. Fetching it works, but it always fails to build. I get this error: 'failed launching cl.exe /P /Zc:preprocessor /PD /nologo ... '. Additionally, a more general question about bindbc, is it possible to skip using dub altogether? Like would placing the bindbc files inside of 'C:\D\dmd2\src\druntime\import' work directly?
Mar 11 2023
On 12/03/2023 3:12 PM, idsize wrote:I started learning D a few weeks ago and am enjoying it so far. I would like to use SDL with D and found bindbc-sdl, but I cannot figure out how to make it work.Welcome!From my understanding, I'll need to use 'dub fetch bindbc-sdl' to download it, and then run 'dub build bindbc-sdl' to build it, before I can use it. Fetching it works, but it always fails to build. I get this error: 'failed launching cl.exe /P /Zc:preprocessor /PD /nologo ... '.You don't need to do that, add it as a dependency in your dub package and dub will do the rest. But ugh that error looks weird. That would imply its trying to run the C preprocessor for ImportC. That does not sound right at all, I don't see any C headers/code in bindbc-sdl repo (not that it needs it). Gonna need to see the entire error log for that to know whats going on (and possibly the verbose output).Additionally, a more general question about bindbc, is it possible to skip using dub altogether? Like would placing the bindbc files inside of 'C:\D\dmd2\src\druntime\import' work directly?Yes, but not that way. Druntime/phobos are both distributed compiled, the import directories tell the compiler what has been compiled in and allow access to templates defined by the library (which you then compile). If you add the appropriate versions and copy the files to your project directory (including bindbc-loader) that should work however as long as you compile it in.
Mar 11 2023
On 12/03/2023 3:24 PM, Richard (Rikki) Andrew Cattermole wrote:But ugh that error looks weird. That would imply its trying to run the C preprocessor for ImportC. That does not sound right at all, I don't see any C headers/code in bindbc-sdl repo (not that it needs it). Gonna need to see the entire error log for that to know whats going on (and possibly the verbose output).Ah huh, there is one! https://github.com/BindBC/bindbc-sdl/blob/master/source/bindbc/sdl/ctypes.c That explains it.
Mar 11 2023
On Sunday, 12 March 2023 at 02:59:20 UTC, Richard (Rikki) Andrew Cattermole wrote:On 12/03/2023 3:24 PM, Richard (Rikki) Andrew Cattermole wrote:So this is a dub issue? It is able to find the linker, why can't it find the preprocessor?But ugh that error looks weird. That would imply its trying to run the C preprocessor for ImportC. That does not sound right at all, I don't see any C headers/code in bindbc-sdl repo (not that it needs it). Gonna need to see the entire error log for that to know whats going on (and possibly the verbose output).Ah huh, there is one! https://github.com/BindBC/bindbc-sdl/blob/master/source/bindbc/sdl/ctypes.c That explains it.
Mar 11 2023
On 12/03/2023 4:01 PM, ryuukk_ wrote:So this is a dub issue?Nope, dub is doing everything ok, this is for ImportC.It is able to find the linker, why can't it find the preprocessor?Its probably not installed. We don't ship a C toolchain, it uses the system one (MSVC, which you would normally get via Visual Studio).
Mar 11 2023
On Sunday, 12 March 2023 at 03:01:24 UTC, ryuukk_ wrote:So this is a dub issue? It is able to find the linker, why can't it find the preprocessor?I tried to use dub several times, and each and every attempt ended in "huh?" things like this. So I stopped trying to use dub, just bringing in source as needed. I know, you have to be like npm otherwise you're irrelevant. Perhaps I was born in the wrong century, although a century ago there'd have been no dlang, and I _like_ this language. :-) Andy
Mar 26
On Sunday, 12 March 2023 at 02:24:31 UTC, Richard (Rikki) Andrew Cattermole wrote:If you add the appropriate versions and copy the files to your project directory (including bindbc-loader) that should work however as long as you compile it in.I've never used a package manager before so the entire process of using one is still strange to me. When using SDL2 with C, I have all of the SDL2 files within my MinGW install. To compile I use 'gcc example.c -lmingw32 -lSDL2 -lSDL2main'. Could I use a method similar to that? Also here is the full (but not verbose) error log: ''' Starting Performing "debug" build using C:\D\dmd2\windows\bin64\dmd.exe for x86_64. Building bindbc-sdl 1.3.0: building configuration [staticBC] failed launching cl.exe /P /Zc:preprocessor /PD /nologo C:\Users\idoug\AppData\Local\dub\packages\bindbc-sdl-1.3.0\bindbc-sdl\source bindbc\sdl\ctypes.c /FIC:\D\dmd2\windows\bin64\..\..\src\drunt me\import\importc.h /Fictypes.i C:\Users\idoug\AppData\Local\dub\packages\bindbc-sdl-1.3.0\bindbc-sdl\source\bindbc\s l\config.d(127,16): Error: C preprocess command cl.exe failed for file C:\Users\idoug\AppData\Local\dub\packages\bindbc-sdl-1.3.0\bindbc-sdl\source\ indbc\sdl\ctypes.c, exit status 1 Error C:\D\dmd2\windows\bin64\dmd.exe failed with exit code 1. '''
Mar 11 2023
On 12/03/2023 4:27 PM, idsize wrote:On Sunday, 12 March 2023 at 02:24:31 UTC, Richard (Rikki) Andrew Cattermole wrote:Yeah pretty much the same thing in principle. Pass the D files to the compiler (including the bindings, dynamic bindings are not like headers, they load the DLL at runtime not during linking like static bindings), tell it the versions needed for the bindings and it should work. When you do a successful build with the verbose flag it'll tell you what commands were used to build and link it. That should give you some pointers of what is required (although there will be extra flags/versions specified that you probably won't need).If you add the appropriate versions and copy the files to your project directory (including bindbc-loader) that should work however as long as you compile it in.I've never used a package manager before so the entire process of using one is still strange to me. When using SDL2 with C, I have all of the SDL2 files within my MinGW install. To compile I use 'gcc example.c -lmingw32 -lSDL2 -lSDL2main'. Could I use a method similar to that?
Mar 11 2023
Hi there, I cloned https://git.sleeping.town/BindBC/bindbc-sdl.git to get the latest SDL bindings for D. In addition I cloned bindbc-loader and bindbc-common and copied the files into the appropriate directories. Then I cloned SDL and SDL_net and built everything in Release mode using Visual Studio 2022. So basically now my project contains the following files: C:\Users\Acer\source\repos\adokhugi\game-d 26.03.2025 18:30 <DIR> . 26.03.2025 17:47 <DIR> .. 26.03.2025 18:25 <DIR> source 26.03.2025 17:50 138 .gitignore 26.03.2025 18:27 5,214 app.obj 26.03.2025 18:25 46 build.bat 26.03.2025 18:27 288 dub.sdl 26.03.2025 18:20 2,515,968 SDL3.dll 26.03.2025 18:20 272,158 SDL3.lib 26.03.2025 18:21 128,000 SDL3_net.dll 26.03.2025 18:21 9,676 SDL3_net.lib The contents of dub.sdl: name "game-d" description "A game coded in D using SDL" authors "Claus D. Volko" copyright "Copyright © 2025, Claus D. Volko" license "proprietary" dependency "bindbc-sdl" version="~>2.1.0" versions "SDL_3_4" "SDL_Net_3_0" libs "SDL3" "SDL3_net" subConfiguration "bindbc-sdl" "staticBC" The preliminary contents of source\app.d: import bindbc.sdl; void main(){ SDL_Init(SDL_INIT_VIDEO); //etc. SDL_Quit(); } So when I try to build this, I get: C:\Users\Acer\source\repos\adokhugi\game-d>dmd source\app.d -L SDL3.lib -L SDL3_net.lib app.obj : error LNK2001: unresolved external symbol _D6bindbc6common7codegen10EnumMember9__xtoHashFNbNeKxSQCaQBwQBsQBnZm app.obj : error LNK2001: unresolved external symbol _D6bindbc6common7codegen10EnumMember11__xopEqualsMxFKxSQCbQBxQBtQBoZb app.obj : error LNK2001: unresolved external symbol _D6bindbc6common7codegen6FnBind6__initZ app.obj : error LNK2001: unresolved external symbol _D6bindbc6common7codegen6FnBind9__xtoHashFNbNeKxSQBvQBrQBnQBiZm app.obj : error LNK2001: unresolved external symbol _D6bindbc6common7codegen6FnBind11__xopEqualsMxFKxSQBwQBsQBoQBjZb app.obj : error LNK2001: unresolved external symbol _D6bindbc6common7codegen8EnumIden9__xtoHashFNbNeKxSQBxQBtQBpQBkZm app.obj : error LNK2001: unresolved external symbol _D6bindbc6common7codegen8EnumIden11__xopEqualsMxFKxSQByQBuQBqQBlZb app.exe : fatal error LNK1120: 7 unresolved externals Error: linker exited with status 1120 C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\link.exe /NOLOGO "app.obj" /DEFAULTLIB:"SDL3.lib" /DEFAULTLIB:"SDL3_net.lib" /DEFAULTLIB:phobos64 /LIBPATH:"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\lib\x64" legacy_stdio_definitions.lib /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\ucrt\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\um\x64" Could anybody please tell me what I have to do in order to get this to work? Thank you very much in advance!
Mar 26
On Wednesday, 26 March 2025 at 17:34:14 UTC, Claus D. Volko wrote:Could anybody please tell me what I have to do in order to get this to work?I don't know what's causing your linker errors related to bindbc-common, but I suggest you start over. Delete all of the BindBC stuff you "copied into appropriate directories". You don't need to any of that because you're using dub. It's both a build tool and a package manager. You have bindbc-sdl as a dependency in your configuration, so dub will pull down bindbc-sdl and everything it depends on. See if you get a successful build after that. Also, please don't resurrect old threads. If you still have issues building after starting over and aren't able to resolve them, please do post in a new thread rather than replying to this one.
Mar 26
On Sunday, 12 March 2023 at 02:12:45 UTC, idsize wrote:I started learning D a few weeks ago and am enjoying it so far. I would like to use SDL with D and found bindbc-sdl, but I cannot figure out how to make it work. From my understanding, I'll need to use 'dub fetch bindbc-sdl' to download it, and then run 'dub build bindbc-sdl' to build it, before I can use it. Fetching it works, but it always fails to build. I get this error: 'failed launching cl.exe /P /Zc:preprocessor /PD /nologo ... '. Additionally, a more general question about bindbc, is it possible to skip using dub altogether? Like would placing the bindbc files inside of 'C:\D\dmd2\src\druntime\import' work directly?Hello, and welcome! Looks like the new version of that library is broken, i am having the same issue Reverting to previous (1.2.4) one is working (delete the dub.selection.json): Download SDL: https://github.com/libsdl-org/SDL/releases/tag/release-2.26.4 And put the dll in your project folder ```json { "name": "hellosdl", "dependencies": { "bindbc-sdl": "1.2.4", }, "versions": [ "SDL_2_26" ], } ``` ```D import bindbc.sdl; import core.stdc.stdio; void main() { // here we load the dll auto ret = loadSDL(); // here handle cases where it failed to load the dll if (ret != sdlSupport) { if (ret == SDLSupport.noLibrary) { // dll not found } else if (ret == SDLSupport.badLibrary) { // wrong DLL, perhaps 32bit vs 64bit? } return; } // all good, let's use SDL SDL_Window* window = null; SDL_Surface* screenSurface = null; if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "could not initialize sdl2: %s\n", SDL_GetError()); return; } window = SDL_CreateWindow("hello_sdl2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN); if (window == null) { fprintf(stderr, "could not create window: %s\n", SDL_GetError()); return; } screenSurface = SDL_GetWindowSurface(window); bool running = true; while (running) { SDL_Event ev; while (SDL_PollEvent(&ev)) { switch (ev.type) { case SDL_QUIT: running = false; break; default: break; } } SDL_FillRect(screenSurface, null, SDL_MapRGB(screenSurface.format, 0x00, 0x00, 0xFF)); SDL_UpdateWindowSurface(window); } SDL_DestroyWindow(window); SDL_Quit(); } ``` I filled an issue on the tracker: https://github.com/BindBC/bindbc-sdl/issues/50
Mar 11 2023
On Sunday, 12 March 2023 at 02:52:27 UTC, ryuukk_ wrote:On Sunday, 12 March 2023 at 02:12:45 UTC, idsize wrote:Thanks! It compiled and ran your example successfully.[...]Hello, and welcome! Looks like the new version of that library is broken, i am having the same issue [...]
Mar 11 2023