Error with identical "expected type"

I’m using freetype+harfbuzz.

When I was trying to compile next code:

    var ft_library: freetype.FT_Library = undefined;
    var ft_face: freetype.FT_Face = undefined;
    var ft_error: freetype.FT_Error = undefined;

    ft_error = freetype.FT_Init_FreeType(&ft_library);
    if (ft_error != 0) freetypePanic("Failed init FreeType!\n");
    defer _ = freetype.FT_Done_FreeType(ft_library);
    ft_error = freetype.FT_New_Face(ft_library, "FiraCodeNerdFont-Regular.ttf", 0, &ft_face);
    if (ft_error != 0) freetypePanic("Failed create new face!\n");
    defer _ = freetype.FT_Done_Face(ft_face);
    ft_error = freetype.FT_Set_Char_Size(ft_face, FONT_SIZE * 64, FONT_SIZE * 64, 0, 0);
    if (ft_error != 0) freetypePanic("Failed set char size!\n");

    const hb_font = harfbuzz.hb_ft_font_create(ft_face, null);

I got next error:

src\main.zig:42:48: error: expected type '[*c]cimport.struct_FT_FaceRec_', found '[*c]cimport.struct_FT_FaceRec_'
    const hb_font = harfbuzz.hb_ft_font_create(ft_face, null);
src\main.zig:42:48: note: pointer type child 'cimport.struct_FT_FaceRec_' cannot cast into pointer type child 'cimport.struct_FT_FaceRec_'
E:\_projects\zig\qgen-next-sdl2\.zig-cache\o\c096b3fe556b85bb8e096e8882be37a5\cimport.zig:2052:39: note: struct declared here
pub const struct_FT_FaceRec_ = extern struct {
E:\_projects\zig\qgen-next-sdl2\.zig-cache\o\23d59c28d5bc660e4866740be0eeb459\cimport.zig:3008:39: note: struct declared here
pub const struct_FT_FaceRec_ = extern struct {
E:\_projects\zig\qgen-next-sdl2\.zig-cache\o\23d59c28d5bc660e4866740be0eeb459\cimport.zig:3142:42: note: parameter type declared here
pub extern fn hb_ft_font_create(ft_face: FT_Face, destroy: hb_destroy_func_t) ?*hb_font_t;

Hey @LegatusMarcus, please show us your cImport statements. It looks like you have multiple cImport’s.


Of course, I have this:

const std = @import("std");
const sdl = @cImport({
const freetype = @cImport({
const harfbuzz = @cImport({

You think there are conflict between hb-ft.h and freetype.h?

My build.zig look like this (if that related somehow):

// ---- SDL2 ----
    exe.addIncludePath(b.path("libs/sdl/include")); // path to header files
    exe.addLibraryPath(b.path("libs/sdl/lib")); // path to .lib files
    b.installBinFile("libs/sdl/lib/SDL2.dll", "SDL2.dll"); // path to .dll files
    exe.linkSystemLibrary("SDL2"); // linking the libraries
    // ---- SDL2 ----

    // ---- FreeType ----
    b.installBinFile("libs/freetype/lib/freetype.dll", "freetype.dll");
    // ---- FreeType ----
    // ---- HarfBuzz ----
    b.installBinFile("libs/harfbuzz/lib/harfbuzz.lib", "harfbuzz.lib");
    // ---- HarfBuzz ----

Try combining these into one cImport statement with all of your includes in one import statement. This will create the error you’re seeing.

Those two types exist in separate locations (and hence they’re seen as different types) because the they’re coming through separate cImports which don’t know about eachother.


Thanks, but looks like harfbuzz already include a freetype :slight_smile:
So, I just comment out freetype import.