const std = @import("std");
pub const std_options: std.Options = .{
.log_level = .debug,
};
const c = @cImport({
@cDefine("SDL_DISABLE_OLD_NAMES", {});
@cInclude("SDL3/SDL.h");
@cInclude("SDL3/SDL_revision.h");
// For programs that provide their own entry points instead of relying on SDL's main function
// macro magic, 'SDL_MAIN_HANDLED' should be defined before including 'SDL_main.h'.
@cDefine("SDL_MAIN_HANDLED", {});
@cInclude("SDL3/SDL_main.h");
});
Ok, I copied the above codes to the main.zig file in src. What should I do now?
Try to create a more minimal version of the main function:
Throwing out stuff like audio, drawing of bricks, etc. only keeping the essential skeleton of the function and try to read and understand what the different parts do. I think that would set you up to have a good understanding of how you can build an sdl application.
And then try whether it can be run via zig build run
zig build
thread 14632 panic: no dependency named 'sdl' in 'D:\oyun-zig\build.zig.zon'. All packages used in build.zig must be declared in this file
C:\zig\lib\std\Build.zig:2159:20: 0x7ff6e388f838 in findPkgHashOrFatal (build.exe.obj)
std.debug.panic("no dependency named '{s}' in '{s}'. All packages used in build.zig must be declared in this file", .{ name, full_path });
^
C:\zig\lib\std\Build.zig:2222:40: 0x7ff6e3871e4e in dependency__anon_67208 (build.exe.obj)
const pkg_hash = findPkgHashOrFatal(b, name);
^
D:\oyun-zig\build.zig:17:33: 0x7ff6e3861a68 in build (build.exe.obj)
const sdl_dep = b.dependency("sdl", .{
^
C:\zig\lib\std\Build.zig:2427:33: 0x7ff6e3857ce2 in runBuild__anon_27568 (build.exe.obj)
.void => build_zig.build(b),
^
C:\zig\lib\compiler\build_runner.zig:339:29: 0x7ff6e3850e27 in main (build.exe.obj)
try builder.runBuild(root);
^
C:\zig\lib\std\start.zig:475:53: 0x7ff6e385a0ef in WinStartup (build.exe.obj)
std.os.windows.ntdll.RtlExitUserProcess(callMain());
^
???:?:?: 0x7ffd2d297373 in ??? (KERNEL32.DLL)
???:?:?: 0x7ffd2e2bcc90 in ??? (ntdll.dll)
error: unable to read results of configure phase from 'D:\oyun-zig\.zig-cache\tmp\5aefe6b7d31252c1': FileNotFound
I looked inside the oyun-zig folder. A file named build.zig.zon was not created. There is none. Only a folder named .zig-cache was created. Multiple folders and files were created inside it. I looked at each one one by one. There is no file named build.zig.zon in any of them.
This is your project directory?
Have you ever called zig init in there?
It should have written something like:
info: created build.zig
info: created build.zig.zon
info: created src/main.zig
info: created src/root.zig
info: see `zig build --help` for a menu of options
yes. my game is in this folder. it is in the game-zig folder in the d drive. the build and main files are in this folder. i don’t understand where zig init is and what it does.
zig init is a command that initializes a new zig project and creates some basic files for a project, similar to how zig build is a command that builds a zig project
I read articles about how to create a project. I couldn’t succeed. I asked chatgpt last. He suggested 30-40 steps. I kept getting errors with each suggestion. He kept updating the codes. He made adjustments. But I never succeeded. He gave various errors every time. When I couldn’t solve the problem, he finally told me to create it manually. I created a folder called oyun-zig in the D drive. There is a src folder in it. There is a file called main.zig in it. There is also build.zig in the main directory. He said that creating these folders and files would be enough. I couldn’t do that as you mentioned, creating a project from the console. I got 40 different errors in 40 attempts.
The files you mentioned have been created.
I did a zig build run again.
the result is below.
D:\oyun-zig>cd /d D:\oyun-zig
D:\oyun-zig>zig build run
thread 8788 panic: no dependency named ‘sdl’ in ‘D:\oyun-zig\build.zig.zon’. All packages used in build.zig must be declared in this file
C:\zig\lib\std\Build.zig:2159:20: 0x7ff6e388f838 in findPkgHashOrFatal (build.exe.obj)
std.debug.panic(“no dependency named ‘{s}’ in ‘{s}’. All packages used in build.zig must be declared in this file”, .{ name, full_path });
^
C:\zig\lib\std\Build.zig:2222:40: 0x7ff6e3871e4e in dependency__anon_67208 (build.exe.obj)
const pkg_hash = findPkgHashOrFatal(b, name);
^
D:\oyun-zig\build.zig:17:33: 0x7ff6e3861a68 in build (build.exe.obj)
const sdl_dep = b.dependency(“sdl”, .{
^
C:\zig\lib\std\Build.zig:2427:33: 0x7ff6e3857ce2 in runBuild__anon_27568 (build.exe.obj)
.void => build_zig.build(b),
^
C:\zig\lib\compiler\build_runner.zig:339:29: 0x7ff6e3850e27 in main (build.exe.obj)
try builder.runBuild(root);
^
C:\zig\lib\std\start.zig:475:53: 0x7ff6e385a0ef in WinStartup (build.exe.obj)
std.os.windows.ntdll.RtlExitUserProcess(callMain());
^
???:?:?: 0x7ffd2d297373 in ??? (KERNEL32.DLL)
???:?:?: 0x7ffd2e2bcc90 in ??? (ntdll.dll)
error: unable to read results of configure phase from ‘D:\oyun-zig.zig-cache\tmp\6a1991fc34c5034e’: FileNotFound