Multiple @cImports, conflicting types

If i have multiple files in project, which contains:

const SDL = @cImport({

i get a not very helpful error message:
error: expected type ‘*cimport.struct_SDL_Texture’, found ‘*cimport.struct_SDL_Texture’

how can i solve this?

and also, one of them is a c-file which has

#include "SDL.h"

My solution to this problem was to create one sdl2_c.zig file and have

pub const SDL = @cImport({

in there and my other zig files import that zig file. Then the Zig compiler worked it out correctly.


I can confirm that this worked for me too.

that works if i can change all the files that uses sdl. Now i have a c-file aswell, SDL_FontCache, so how to solve that? can i translate it into a zig file somehow?

i dont see how i can use any other c-libs that depend on sdl, if its going to give conflicts like above?

SDL_FontCache is a normal C library. What you’d do is compile SDL_FontCache to a shared library (dll or so), import the SDL_FontCache header file and link against it.

There is a way to translate C code to Zig code, but if you just want to use functionality of a library, that’s not necessary.

On the question how does that play into the previous error: What’s speaking against putting the include for SDL_FontCache into the sdl cImport, too?

1 Like

ah i wasnt using it as a C library, just as a C-source file. Will try to do it as a library instead!

1 Like

Im sorry, this question isnt related to zig, but how do i compile FontCache to a shared library on linux? running the CMakeList.txt and then make, gives me a libFontCache.a-file, which i understand is a static library. how to get the .so-file? grateful for any help, i also asked on FontCache’s github, but the last post on “issues” was a year ago, so not expecting a answer anytime soon.