Error zig expected type 'cimport.struct_Vector2', found 'cimport.struct_Vector2'

Hi, I 'm new to zig, I’m working on a small project with raylib bindings (direct no use of zig raylib library) this is my imports:

const std = @import("std");
const expect = std.testing.expect;
const rl = @cImport(@cInclude("raylib.h"));
const rlm = @cImport(@cInclude("raymath.h"));
const Vector2 = rl.Vector2;

in this line of code

fn apply_vec(self:@This(), p: Vector2) Vector2 {
            return  rlm.Vector2Add(rlm.Vector2Scale(p, self.scale), self.origin);
        }

apply_vec is function inside a structure which defines origin (vector2) and scale (f32)
I have a strange (tautoligical) error:


error: expected type 'cimport.struct_Vector2', found 'cimport.struct_Vector2'
            return  rlm.Vector2Add(rlm.Vector2Scale(p, self.scale), self.origin);
                                                                             ^

I wonder what does that mean? it’s sound like a conflict of Vector2 definition (?)

Vector2Add is defined in raymath.h:

// Add two vectors (v1 + v2)
RMAPI Vector2 Vector2Add(Vector2 v1, Vector2 v2)
{
    Vector2 result = { v1.x + v2.x, v1.y + v2.y };
    return result;
}

in the rest of the error text it’s mentionned that struct_Vector2 is defined in two files of zig-cache\o\crypticfolder1\cimport.zig and zig-cache\o\crypticfolder2\cimport.zig

Hello @imwd
welcome to ziggit :slight_smile:

I think the two cImport redeclare Vector2.
Try to combine the two cInclude in one cImport.

const rl = @cImport({
    @cInclude("raylib.h");
    @cInclude("raymath.h");
});
4 Likes

Dimdin you nail it! Very nice solution. I can continue my work. Thank you very much. (I’m also one step further in understanding ZIG)

1 Like