How to a link to a C library to create static bindings?
thebluepandabear
therealbluepandabear at protonmail.com
Sat Jan 28 02:40:58 UTC 2023
Hello,
I am wanting to create my own C bindings to CSFML, and I have
been extremely struggling with this.
There is no resources or tutorials for how to do this so I am
basically on my own.
First thing I looked at was `dstep` which helps translate C
header files to D language, so I ran `dstep` and translated the C
header files to D language. This went well. I ended up wrapping
all the code in an `extern(C)` call.
Now, I am trying to 'link' CSFML to my bindings but have been
struggling to do so.
I tried to add the following to `dub.json`:
```
"libs": ["csfml-audio", "csfml-graphics"]
```
But it came back with an error:
```
/usr/bin/ld:
/home/tom/Desktop/sfmld-backend/out/production/sfmld-backend/obj/sfmld-backend.o: in function `_Dmain':
/home/tom/Desktop/sfmld-backend/source/graphics.d:(.text._Dmain[_Dmain]+0x3a): undefined reference to `sfRenderWindow_create'
/usr/bin/ld:
/home/tom/Desktop/sfmld-backend/source/graphics.d:(.text._Dmain[_Dmain]+0x58): undefined reference to `sfRenderWindow_isOpen'
/usr/bin/ld:
/home/tom/Desktop/sfmld-backend/source/graphics.d:(.text._Dmain[_Dmain]+0x69): undefined reference to `sfRenderWindow_pollEvent'
/usr/bin/ld:
/home/tom/Desktop/sfmld-backend/source/graphics.d:(.text._Dmain[_Dmain]+0x7c): undefined reference to `sfRenderWindow_close'
/usr/bin/ld:
/home/tom/Desktop/sfmld-backend/source/graphics.d:(.text._Dmain[_Dmain]+0x90): undefined reference to `sfRenderWindow_clear'
/usr/bin/ld:
/home/tom/Desktop/sfmld-backend/source/graphics.d:(.text._Dmain[_Dmain]+0x99): undefined reference to `sfRenderWindow_display'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
```
I am really confused as to how I even am supposed to get the
library name in the first place, which is another thing that is
confusing me.
Any help with this would be appreciated.
More information about the Digitalmars-d-learn
mailing list