Step by step tutorials for using bindings in D

eXodiquas exodiquas at gmail.com
Sun Mar 26 18:49:57 UTC 2023


On Sunday, 26 March 2023 at 14:09:19 UTC, Inkrementator wrote:
>
> # Practical Walkthrough
> Two ways to go about this:
> 1. Get SFML dynamic library somewhere
> 2. Create a project called sfmltest
> 3. Add BindBC-SFML dependency via dub
> 4. Put SFML dynamic library files into the directory where you 
> will execute your file.
> Here we see that the dynamic bindings looks for the lib in the 
> current directory: 
> https://github.com/BindBC/bindbc-sfml/blob/a1bc81da5c41ec49257228a29dc0f30ec7e5c788/source/bindbc/sfml/system.d#L215
>
> You can also use static bindings, but that will involve telling 
> your linker about the library. I won't go into detail but it 
> basically boils down to installing SFML to system directory or 
> LD_LIBRARY_PATH and compiling your test project with -lSFML 
> flag, or whatever the option is for dub.
> If you can install it via your package-manager, static bindings 
> might be less of a hassle. And learning the process is worth 
> it, you'll need it in the future, since dynamic binding are the 
> exception.

Thank you very much for your detailed answer. I got dynamic 
bindings running now. But you said static bindings are the main 
portion of bindings we use. So I tried to get static Lua bindings 
going. I got the static library `liblua.a` and I told my linker 
in the dub.json file where to find it:

```json
   [...]
   "versions": ["LUA_52"],
   "lflags": ["-L/usr/local/lib/liblua.a"],
   [...]
```

This works perfectly fine. I can also use `"libs": ["lua"]` so I 
don't have to specify the complete path. But now I wonder, do I 
have to specify all static bindings via linker commands or is 
there a mechanism which allows me to specify a path where all the 
libraries can be found? And my other question is, if I have to 
specify all static libraries by name, how do I know the name of 
the library? Giving the system path as `lflag` is easy, but where 
does Lua get the `lua` name from which works in the `"libs": 
["lua"]` string?

Thanks for answering my noob questions. I've never dealt with 
bindings and compiler flags in the languages I come from. :P


More information about the Digitalmars-d-learn mailing list