digitalmars.D.learn - bindbc, SDL
- Claus D. Volko (61/61) Mar 26 Hi there,
- Claus D. Volko (33/33) Mar 26 Well, I've now used dub build and am basically getting the same
- Claus D. Volko (3/3) Mar 26 It did build without errors after I removed the line
- Claus D. Volko (4/4) Mar 26 Well, well.
- ryuukk_ (3/8) Mar 27 If you are using the shared library instead of the static
- Claus D. Volko (7/9) Mar 27 Judging from what's written on
- Richard (Rikki) Andrew Cattermole (9/18) Mar 27 Shared libraries on Windows (DLL)'s, produce when linked an import
- Mike Parker (25/30) Mar 27 Let's get our terminology straight here.
- Claus D. Volko (3/3) Mar 27 I got my program to work. The DLL files had been missing and I
- Mike Parker (4/9) Mar 27 What do you mean by "fails"? Did you mean you the function call
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! PS: I don't know how to use dub.
Mar 26
Well, I've now used dub build and am basically getting the same issues: C:\Users\Acer\source\repos\adokhugi\game-d>dub build Fetching bindbc-sdl 2.1.0 (getting selected version) Fetching bindbc-common 1.0.5 (getting selected version) Fetching bindbc-loader 1.1.5 (getting selected version) Starting Performing "debug" build using c:\D\dmd2\windows\bin64\dmd.exe for x86_64. Building bindbc-common 1.0.5: building configuration [yesBC] Building bindbc-sdl 2.1.0: building configuration [staticBC] Building game-d ~master: building configuration [application] Linking game-d game-d.obj : error LNK2001: unresolved external symbol _D6bindbc6common7codegen10EnumMember9__xtoHashFNbNeKxSQCaQBwQBsQBnZm game-d.obj : error LNK2001: unresolved external symbol _D6bindbc6common7codegen10EnumMember11__xopEqualsMxFKxSQCbQBxQBtQBoZb game-d.obj : error LNK2001: unresolved external symbol _D6bindbc6common7codegen6FnBind9__xtoHashFNbNeKxSQBvQBrQBnQBiZm game-d.obj : error LNK2001: unresolved external symbol _D6bindbc6common7codegen6FnBind11__xopEqualsMxFKxSQBwQBsQBoQBjZb game-d.obj : error LNK2001: unresolved external symbol _D6bindbc6common7codegen8EnumIden9__xtoHashFNbNeKxSQBxQBtQBpQBkZm game-d.obj : error LNK2001: unresolved external symbol _D6bindbc6common7codegen8EnumIden11__xopEqualsMxFKxSQByQBuQBqQBlZb C:\Users\Acer\AppData\Local\dub\cache\game-d\~master\build\application-debug-4FODLXa9OHT8X 3ikm9oOA\game-d.exe : fatal error LNK1120: 6 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 "C:\Users\Acer\AppData\Local\dub\cache\game-d\~master\build\application-debug-4FODLXa9OHT8XG ikm9oOA\game-d.obj" /OUT:"C:\Users\Acer\AppData\Local\dub\cache\game-d\~master\build\application-debug-4FODLXa9OHT8XG ikm9oOA\game-d.exe" /DEFAULTLIB:"C:\Users\Acer\AppData\Local\dub\cache\bindbc-sdl\2.1.0\build\staticBC-debug-R5AUcUVlHWC2H6QGJ2 qNw\BindBC_SDL.lib" /DEFAULTLIB:"C:\Users\Acer\AppData\Local\dub\cache\bindbc-common\1.0.5\build\yesBC-debug-V-NThw1EUFmiU6cRIF0tF \BindBC_Common.lib" /DEFAULTLIB:"SDL3.lib" /DEFAULTLIB:"SDL3_net.lib" /DEFAULTLIB:phobos64 /DEBUG /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" Error c:\D\dmd2\windows\bin64\dmd.exe failed with exit code 1.
Mar 26
It did build without errors after I removed the line subConfiguration "bindbc-sdl" "staticBC" from dub.sdl.
Mar 26
Well, well. Now my code builds but it seems that the call of SDL_Init fails. I wonder if SDL3.lib is okay since I built it myself using Visual Studio. Maybe there is some prebuilt version available somewhere?
Mar 26
On Thursday, 27 March 2025 at 06:17:28 UTC, Claus D. Volko wrote:Well, well. Now my code builds but it seems that the call of SDL_Init fails. I wonder if SDL3.lib is okay since I built it myself using Visual Studio. Maybe there is some prebuilt version available somewhere?If you are using the shared library instead of the static library, you need to load it, call the `loadSDL` function
Mar 27
On Thursday, 27 March 2025 at 07:40:38 UTC, ryuukk_ wrote:If you are using the shared library instead of the static library, you need to load it, call the `loadSDL` functionJudging from what's written on https://en.wikipedia.org/wiki/Shared_library it should actually be a static library as it's a .lib file. Maybe the reason for the problem is that I compiled the library in Release mode while I built the D project in Debug mode? Anyway, I'll also try using the loadSDL function, thank you for the advice.
Mar 27
On 28/03/2025 3:06 AM, Claus D. Volko wrote:On Thursday, 27 March 2025 at 07:40:38 UTC, ryuukk_ wrote:Shared libraries on Windows (DLL)'s, produce when linked an import library that happens to be a static library. You link to the import library when you want to link against the shared library during compilation. It provides the information to the linker that it needs for this process. The bindbc family of packages, usually can link against a shared library both during compilation (statically), or during runtime (dynamically). The import library serves no purpose if you are linking dynamically.If you are using the shared library instead of the static library, you need to load it, call the `loadSDL` functionJudging from what's written on https://en.wikipedia.org/wiki/ Shared_library it should actually be a static library as it's a .lib file. Maybe the reason for the problem is that I compiled the library in Release mode while I built the D project in Debug mode? Anyway, I'll also try using the loadSDL function, thank you for the advice.
Mar 27
On Thursday, 27 March 2025 at 14:10:21 UTC, Richard (Rikki) Andrew Cattermole wrote:The bindbc family of packages, usually can link against a shared library both during compilation (statically), or during runtime (dynamically). The import library serves no purpose if you are linking dynamically.Let's get our terminology straight here. BindBC supports static bindings and dynamic bindings. Static bindings are used for both static and dynamic linking, i.e., there is a link-time dependency. Static linking means linking to the static library and there is no runtime dependency. Dynamic linking means linking with the import library on Windows and the dynamic library on other platforms, in which case there's a runtime dependency on the shared library. Dynamic bindings are used for *dynamic loading*, not dynamic linking. This means there is no link-time dependency, but there is still a runtime dependency on the shared library. In this case, the shared library must be loaded manually at runtime. In a static binding, the C function are declared as normal function declarations. When statically linking, the linker matches the symbols up. When dynamically linking, the system loader loads the shared library and then matches the symbols up. In a dynamic binding, the C functions are declared as function pointers. The programmer must get a handle to the shared library via a system API call, then use the handle to fetch a pointer to each of the library's functions (or just the ones needed) and assign them to the function pointers declared by the binding. That's what bindbc-loader does, and why functions like `loadSDL` need to be called first when using the dynamic binding.
Mar 27
I got my program to work. The DLL files had been missing and I had to include a call to loadSDL. That was all that had to be done. Hooray! Thanks again for your help.
Mar 27
On Thursday, 27 March 2025 at 06:17:28 UTC, Claus D. Volko wrote:Well, well. Now my code builds but it seems that the call of SDL_Init fails. I wonder if SDL3.lib is okay since I built it myself using Visual Studio. Maybe there is some prebuilt version available somewhere?What do you mean by "fails"? Did you mean you the function call happened but returned an error? Or was it something else, like a null pointer access?
Mar 27