#importing, running examples raylib 0.12dev version WSL2 ubuntu windows 11
1 messages · Page 1 of 1 (latest)
install transitive failure
└─ install raylib-example transitive failure
└─ zig build-exe raylib-example Debug native transitive failure
├─ zig build-lib raygui Debug native transitive failure
│ └─ zig build-lib raylib Debug native failure
└─ zig build-lib raylib Debug native (+1 more reused dependencies)
error: the following build command failed with exit code 1:
/home/joe/td/raylib/raylib-zig/raylib-example/zig-cache/o/4cc65830e3ac586ba943015441152c1f/build /home/joe/zig-linux-x86_64-0.12.0-dev.3125+a7a5f4cf4/zig /home/joe/td/raylib/raylib-zig/raylib-example /home/joe/td/raylib/raylib-zig/raylib-example/zig-cache /home/joe/.cache/zig --seed 0x5ebbc77b -Z73dc07f0791d8dce```
https://ziggit.dev/t/a-simple-example-of-calling-a-c-library-from-zig/2225
tried this, but no proper output
I’m a newcomer to Zig, but I met Andrew Kelly and several other Zig developers at Handmade Seattle this week, and it motivated me to start experimenting with the language. I had a hard time finding simple, complete documentation about how to call C code from Zig. I pieced together a solution from a few different sources and then documented what...
Can you be a bit more specific on what you mean by "import"?
Do you mean "using @import" ?
If so, on what and in what file?
That strange message is I think what the default zig init produces in the generates main.zig.
It's a hello world message essentially, IIRC
use-pgcd.zig
const std = @import("std");
const c = @cImport(@cInclude("pgcd.c")); // No need to have a .h
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const args = try std.process.argsAlloc(allocator);
defer std.process.argsFree(allocator, args);
if (args.len != 3) {
std.debug.print("Usage: find-pgcd L R\n", .{});
return error.WrongArgs;
}
var l = try std.fmt.parseInt(u32, args[1], 10);
var r = try std.fmt.parseInt(u32, args[2], 10);
std.debug.print("PGCD({d},{d}) = {d}\n", .{ l, r, c.pgcd(l, r) });
}
const expect = @import("std").testing.expect;
fn expectIdentical(i: u32) !void {
try expect(c.pgcd(i, i) == i);
}
test "identical" {
try expectIdentical(1);
try expectIdentical(7);
try expectIdentical(18);
}
test "primes" {
try expect(c.pgcd(4, 13) == 1);
}
test "pgcdexists" {
try expect(c.pgcd(15, 35) == 5);
}
test "pgcdlower" {
try expect(c.pgcd(15, 5) == 5);
}
pgcd.c
unsigned int pgcd(unsigned int l, unsigned int r) {
while (l != r) {
if (l > r) {
l = l - r;
} else {
r = r - l;
}
}
return l;
}
/home/joe/zi/test_ziggit/build.zig:4:34:
const exe = b.addExecutable(.{
^
/home/joe/zig-linux-x86_64-0.12.0-dev.3125+a7a5f4cf4/lib/std/Build.zig:638:31:
note: struct 'Build.ExecutableOptions' declared here
pub const ExecutableOptions = struct {
^
referenced by:
runBuild__anon_8909: /home/joe/zig-linux-x86_64-0.12.0-dev.3125+a7a5f4cf4/lib/std/Build.zig:1992:27
main: /home/joe/zig-linux-x86_64-0.12.0-dev.3125+a7a5f4cf4/lib/build_runner.zig:310:29
remaining reference traces hidden; use '-freference-trace' to see all reference traces
i really tested a few other examples but either there is an error or weird output message i mentioned at the start of this post
if there is an easy import/include test if it works let me know, i really think i cant do stuff on wsl
oh zig build install worked but the same output
It seems to me that your build.zig needs fixing.
Generally, you do something like
const optimize = b.standardOptimzeOptions();
const exe = b.addExecutable(.{
.target = optimize,
...
};
zig run does not use build.zig.
hmm
zig build run
zig build produces no output
didnt work before becaue i didnt do zig build install
oh no
i was not in the directory ( i was testing something else before )
sorry
please take a look if this works on your end:
ill try how it works on windows 11 without wsl
This is a successful run of the example main.zig file generated by zig init. Look in src/main.zig and you will find the weird message. What were you expecting to see?
^
zig build will produce no output if it succeeds.
no? there is no mention of that, well whatever im doing something else, ill try to fix it myself
It's ultimately the file in the build.zig that matters.
Double check that is that main.zig
build.zig
const std = @import("std");
const raylib_build = @import("libs/raylib/src/build.zig");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const raylib = raylib_build.addRaylib(b, target, optimize, .{});
const exe = b.addExecutable(.{
.name = "hello",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
exe.linkLibC();
exe.linkLibrary(raylib);
exe.addIncludePath("raylib/src");
exe.install();
const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const exe_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&exe_tests.step);
}```
why is it so hard
seems like there is no working import/cImport/include for my machine
https://github.com/SimonLSchlee/zigraylib tried this
ok this worked...
sudo apt install freeglut3-dev
nvm it didnt work
You're still getting these errors?
well yk i have no idea how to fix copy paste different tabs and formatting on wsl ill just give ss
@compact dragon
lol
That's Raylib's build.zig not being up to date enough for master zig
0.12 version?
Go into raylib/src/build.zig and change the declaration of srclib to just be
const srcdir = "src";
(I vendored raylib, so I can just do that)
[Edit: correct path lol]
ah... i forgot to even clone raylib but lets see if it changes sometihng on windows
[Edit: correct variable name lol]
const srcdir = struct {
fn getSrcDir() []const u8 {
return std.fs.path.dirname(@src().file).?;
}
}.getSrcDir();```
->
```ts
const srcdir = "src";
?
Indeed
oh not in this directory ig
@compact dragon
what is this rcore.c?
0.12.0-dev.3125+a7a5f4cf4```
It's one of Raylib's C files that Zig will build.
That makes me think that it didn't actually use the file you changed
lets clear cache then
no
https://github.com/SimonLSchlee/zigraylib
this is what ive used
idk probably im doing just something really dumb
oh right
it fetches probably from the github repo
not the local file
well
can you give me some code i can test on?
all the code ive found is outdated (for raylib)
When I said I vendored it
I mean that I cloned the upstream Raylib repo
And then put this in my build.zig.zon:
.dependencies = .{
.raylib = .{
.path = "pkg/raylib",
},
},
Where pkg is just a folder of my choosing
+ git submodule add https://github.com/raysan5/raylib.git
or
- git clone https://github.com/raysan5/raylib.git
im not good enough to understand that
I used git subtree
Something like git subtree add --prefix pkg/raylib https://github.com/raysan5/raylib.git master
i really just want to import "a" library, raylib may be too challenging
becasue it seems like nothing is working
the most minimal test
You should have a build.zig.zon next to your build.zig
.name = "zigraylib",
.version = "0.0.1",
.dependencies = .{
.raylib = .{
.url = "https://github.com/raysan5/raylib/archive/e52ae870f297961b9ac23d2e6eca4937a24ac6c0.tar.gz",
.hash = "1220b9dc848ba1359453ce8a68fa844bcbc2cacda462b47498f12d3fd932c63390ee",
},
},
.paths = .{
"build.zig",
"build.zig.zon",
"README.md",
"src",
},
}```
If you want to vendor raylib
Then change use .path instead of .url, and remove .hash
Or yeah - that is what zigraylib's build.zig.zon looks like
I started out using some sort of helper zig package for raylib, but it wasn't that great, so I switched to just using upstream raylib
idk...
isnt there a working code for raylib
so i can just copy and test
dont you have a workign project
or something
@compact dragon
I do, but alas it's not public code.
hm
And I've already told you the important parts anyhow
The only part I don't quite remember is the exact git subtree command I used
But it was along these lines
Might be main instead of master - I forget what name they use
ok ill just wont import stuff
my use for zig isnt that big
and this is too complicated and time consuming
thank you for your help
Alright o7
lol
I would absolutly recommend against using git submodules
in this case it's a case of updating the dependency
for my raylib example which it was the original test, I only had to do zig fetch https://github.com/raysan5/raylib/archive/25caf14be8d0284aceaa0de28753b3012e71b7bb.tar.gz --save=raylib
and now it's updated: https://github.com/Deecellar/raylib-example/
do you have that example somewhere?
oh
thank you so much, will try
@halcyon goblet it works... But how?
Basically, having the correct version of the import, and my config in build.zig
[SOLVED] Hey i cant seem to import anything on WSL on Windows 11