Still can't compile included c files

trying again to add a couple of c files to my test project, still getting errors, i checked my env, and this is what i got
Screenshot from 2024-06-16 21-23-15

im on solus os, is this the reason why zig won’t compile c code ? and how can i fix it ?

How are trying to compile and what error are you getting?


Your environment is fine.
Mine is:

❯ zig env
{
 "zig_exe": "/home/din/zig-0.13.0/zig",
 "lib_dir": "zig-0.13.0/lib",
 "std_dir": "zig-0.13.0/lib/std",
 "global_cache_dir": "/home/din/.cache/zig",
 "version": "0.13.0",
 "target": "x86_64-linux.6.1...6.1-gnu.2.36",
 "env": {
  "ZIG_GLOBAL_CACHE_DIR": null,
  "ZIG_LOCAL_CACHE_DIR": null,
  "ZIG_LIB_DIR": null,
  "ZIG_LIBC": null,
  "ZIG_BUILD_RUNNER": null,
  "ZIG_VERBOSE_LINK": null,
  "ZIG_VERBOSE_CC": null,
  "ZIG_BTRFS_WORKAROUND": null,
  "ZIG_DEBUG_CMD": null,
  "CC": null,
  "NO_COLOR": null,
  "CLICOLOR_FORCE": null,
  "XDG_CACHE_HOME": null,
  "HOME": "/home/din"
 }
}

❯ zig libc
# The directory that contains `stdlib.h`.
# On POSIX-like systems, include directories be found with: `cc -E -Wp,-v -xc /dev/null`
include_dir=/usr/include

# The system-specific include directory. May be the same as `include_dir`.
# On Windows it's the directory that includes `vcruntime.h`.
# On POSIX it's the directory that includes `sys/errno.h`.
sys_include_dir=/usr/include/x86_64-linux-gnu

# The directory that contains `crt1.o` or `crt2.o`.
# On POSIX, can be found with `cc -print-file-name=crt1.o`.
# Not needed when targeting MacOS.
crt_dir=/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu

# The directory that contains `vcruntime.lib`.
# Only needed when targeting MSVC on Windows.
msvc_lib_dir=

# The directory that contains `kernel32.lib`.
# Only needed when targeting MSVC on Windows.
kernel32_lib_dir=

# The directory that contains `crtbeginS.o` and `crtendS.o`
# Only needed when targeting Haiku.
gcc_dir=

Screenshot from 2024-06-16 22-25-09
Screenshot from 2024-06-16 22-25-19
Screenshot from 2024-06-16 22-25-39


test.c is not included in the build
Use addCSourceFile to compile it and link with it.

exe.addCSourceFile(.{.file = b.path("src/test.c")});
3 Likes

it worked, thnx, so i have to include every single file in the build file ? just pointing it towards a path is not enough ?

You must include all the C files.
See also: Build system tricks