#What are specific steps to be able to use a library like sdl2?

1 messages · Page 1 of 1 (latest)

opaque elm
#

I am not really familiar with Zig's package manager,
I looked up online and there is a "build.zig.zon" you need to use, correct but every online post has their own method, and am not sure wethere I am suposed to manually add this build.zig.zon to my project folder.
Some very specific steps would be appreciated.

worldly finch
#

idk either, but iirc there small projects that do this on github that may be just enough of an example to get it done. Havent watched it yet but Dude the Builder has been pretty useful and he has a videos on the general subject:

https://youtu.be/dHmw-424CMY?si=YkZ_g9OlY6ecX-6E

https://youtu.be/OQLZxserr70?si=gplsokZVSz9e4m6X

https://youtu.be/GHwKVf5Idq4?si=u9hbM58E-l50LcwB

Help me create more content like this!
https://www.paypal.com/donate/?hosted_button_id=Y6DEFHEEWVBXJ

Zig's interoperability with C is seamless and top-notch. You can integrate C code directly in your Zig code, or you can compile C to a library and then link that library to Zig. In this episode we cover both approaches and as a bonus, how to com...

▶ Play video

Help me create more content like this!
https://www.paypal.com/donate/?hosted_button_id=Y6DEFHEEWVBXJ

You can add Zig dependencies to your project by first defining them in the build.zig.zon file, then adding them to the parts of your project that need them via the build.zig file. In this episode, we cover a simple example of using a dependency ...

▶ Play video

Help me create more content like this!
https://www.paypal.com/donate/?hosted_button_id=Y6DEFHEEWVBXJ

Zig's build system allows you to define options that your users can specify at build time via command line flags. You can then use these options to make build-time conditional compilation decisions and even propagate and make available these opt...

▶ Play video
digital cloud
#

I have not tested it, but you don't have to use the package manager. If you initialized your project with zig init-exe:
-> build.zig

// [...]
  exe.linkSystemLibrary("SDL2");
// [...]

-> main.zig

const sdl = @cImport({
  @cInclude("SDL2/SDL.h");
});
// [...]

this assumes you have the headers(I think they are called this way?)/package installed on your system. I'm very new to zig or C, and you might need to adjust the paths, but this worked with raylib for me.

plush torrent
#

I tried both importing sdl manually and using zsdl. The latter worked much better for me

opaque elm
#

zsdl?

opaque elm
digital cloud
#

try all capital letters "SDL2"

#

this is how my build.zig looks
tried SDL_GETPLATFORM() and it returned Linux so I guess it works

opaque elm
#

on rust as a dependency it works fine, so sdl2 is deffo correctly installed
Dont know what could be wrong...

signal current
opaque elm
#

hmmm interestingly painful

signal current
digital cloud