again, I am still in following the example at Documentation - The Zig Programming Language
I have mathtest.h
generated
#include "zig.h"
zig_extern int32_t add(int32_t const a0, int32_t const a1);
zig_extern zig_noreturn void abort(void);
zig_extern uint32_t _dyld_image_count(void);
zig_extern struct mach_header__4062 *_dyld_get_image_header(uint32_t const a0);
zig_extern uintptr_t _dyld_get_image_vmaddr_slide(uint32_t const a0);
zig_extern uint8_t const *_dyld_get_image_name(uint32_t const a0);
zig_extern int getcontext(struct ucontext_t__6139 *const a0);
zig_extern void os_unfair_lock_lock(struct os_unfair_lock__2521 *const a0);
zig_extern int pthread_threadid_np(void *const a0, uint64_t *const a1);
zig_extern void *mmap(void *const a0, uintptr_t const a1, unsigned int const a2, unsigned int const a3, int const a4, int64_t const a5);
zig_extern int *__error(void);
zig_extern void os_unfair_lock_unlock(struct os_unfair_lock__2521 *const a0);
zig_extern int sigaction(int const a0, struct Sigaction__2796 const *const a1, struct Sigaction__2796 *const a2);
zig_extern int close$NOCANCEL(int const a0);
zig_extern intptr_t read(int const a0, uint8_t *const a1, uintptr_t const a2);
zig_extern int __ulock_wait2(uint32_t const a0, void const *const a1, uint64_t const a2, uint64_t const a3, uint64_t const a4);
zig_extern int munmap(void const *const a0, uintptr_t const a1);
zig_extern uint8_t *getenv(uint8_t const *const a0);
zig_extern int openat(int const a0, uint8_t const *const a1, unsigned int const a2, ...);
zig_extern int fcntl(int const a0, int const a1, ...);
zig_extern intptr_t write(int const a0, uint8_t const *const a1, uintptr_t const a2);
zig_extern int isatty(int const a0);
zig_extern int msync(void const *const a0, uintptr_t const a1, int const a2);
and copied the test.c
from doc
// This header is generated by zig from mathtest.zig
#include "mathtest.h"
#include <stdio.h>
int main(int argc, char **argv) {
int32_t result = add(42, 1337);
printf("%d\n", result);
return 0;
}
so if zig cc -c test.c
, will see
In file included from test.c:4:
./mathtest.h:1:10: fatal error: 'zig.h' file not found
1 | #include "zig.h"
| ^~~~~~~
1 error generated.
so it is include path problem, I then managed find ‘zig.h’, and do this zig cc -c -I <path-to>/.asdf/installs/zig/0.12.0-dev.1828+225fe6ddb/lib
I will see
In file included from test.c:4:
In file included from ./mathtest.h:1:
/Users/bytedance/.asdf/installs/zig/0.12.0-dev.1828+225fe6ddb/lib/zig.h:1756:26: error: use of undeclared identifier 'ZIG_TARGET_MAX_INT_ALIGNMENT'
1756 | uint16_t alignment = ZIG_TARGET_MAX_INT_ALIGNMENT;
| ^
In file included from test.c:4:
./mathtest.h:8:34: warning: declaration of 'struct ucontext_t__6139' will not be visible outside of this function [-Wvisibility]
8 | zig_extern int getcontext(struct ucontext_t__6139 *const a0);
| ^
./mathtest.h:9:44: warning: declaration of 'struct os_unfair_lock__2521' will not be visible outside of this function [-Wvisibility]
9 | zig_extern void os_unfair_lock_lock(struct os_unfair_lock__2521 *const a0);
| ^
./mathtest.h:13:46: warning: declaration of 'struct os_unfair_lock__2521' will not be visible outside of this function [-Wvisibility]
13 | zig_extern void os_unfair_lock_unlock(struct os_unfair_lock__2521 *const a0);
| ^
./mathtest.h:14:47: warning: declaration of 'struct Sigaction__2796' will not be visible outside of this function [-Wvisibility]
14 | zig_extern int sigaction(int const a0, struct Sigaction__2796 const *const a1, struct Sigaction__2796 *const a2);
| ^
4 warnings and 1 error generated.
seems this ZIG_TARGET_MAX_INT_ALIGNMENT
is defined by zig build system somehow.
but do we have a way to make this zig cc
command line works, or event clang/gcc
works?