i have a small c bitmap implementation that includes, a header c, a bitmap.c and a main.c, i then used the code:
pub const import_c = @cImport({
@cDefine("BITMAP_H", {});
@cInclude("bitmap.h");
});
i compiled with “zig build-exe main.zig -lc -I /home/alice7/.dev/day8/bitmap/zig/src”, the “-I” was because zig cant find the bitmap.h, which they are all in the same directory.
after that, i had error:
zig build-exe main.zig -lc -I /home/alice7/.dev/day8/bitmap/zig/src
main.zig:23:17: error: root source file struct 'cimport' has no member named 'bitmap_create'
_ = import_c.bitmap_create(rows, cols);
~~~~~~~~^~~~~~~~~~~~~~
/home/alice7/.dev/day8/bitmap/zig/.zig-cache/o/12ba35f73bd6c6fb58ff4052278a3ce1/cimport.zig:1:1: note: struct declared here
pub const __builtin_bswap16 = @import("std").zig.c_builtins.__builtin_bswap16;
^~~
referenced by:
main: /nix/store/whqfx1y8x9274qhqvfamyyp4157b9l1a-zig-0.14.0-dev.2639+15fe99957/lib/std/start.zig:656:37
comptime: /nix/store/whqfx1y8x9274qhqvfamyyp4157b9l1a-zig-0.14.0-dev.2639+15fe99957/lib/std/start.zig:58:30
2 reference(s) hidden; use '-freference-trace=4' to see all references
truth is, the bitmap.h has everything correctly stated, because i tested those c programs by running gcc, they works fine, and here is the bitmap.h file, you can clearly see, ‘bitmap_create’ is there:
#ifndef BITMAP_H
#define BITMAP_H
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
/**
* struct Bitmap
* brief A bitmap data structure to store binary data.
*/
typedef struct {
uint64_t* rows; ///< Array of uint64_t values representing the bitmap.
int num_rows; ///< Number of rows in the bitmap.
} Bitmap;
/**
* brief Creates a new bitmap with the specified number of rows and columns.
*
* param rows The number of rows in the bitmap.
* param cols The number of columns in the bitmap.
* return A pointer to the newly created bitmap, or NULL on failure.
*/
Bitmap* bitmap_create(int rows, int cols);
/**
* brief Sets a bit in the bitmap at the specified row and column to 1.
*
* param b The bitmap to modify.
* param row The row index of the bit to set.
* param col The column index of the bit to set.
*/
void bitmap_set_bit(Bitmap* b, int row, int col);
/**
* brief Retrieves the value of a bit in the bitmap at the specified row and column.
*
* param b The bitmap to query.
* param row The row index of the bit to retrieve.
* param col The column index of the bit to retrieve.
* return 1 if the bit is set, 0 otherwise.
*/
int bitmap_get_bit(Bitmap* b, int row, int col);
#endif // BITMAP_H
at this point, i am very lost as to how to troubleshot, also, i do not like using zig build-exe main.zig, within ./src, i want to build like, zig build run, i found something could be useful: Using a single-header C library from Zig, but i cant apply the exact logic to my own code here, since it does not even compile, and zig documentation about using c code is little to none, where do i even search for the correct compile command based on different situations? here, it really isnt very complicated case, imho.
anyone with some ideas willing to share are greatly appreciated