Zig Version
0.16.0, 0.17.0-dev.296+a85a29ae4
Steps to Reproduce and Observed Behavior
- add an import using
b.addTranslateCin build.zig - set
link_libcto true - compile with -fincremental, and run the program
for example:
lib.h:
#include <stdio.h>
build.zig:
var translate_c = b.addTranslateC(.{
.root_source_file = b.path("src/lib.h"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
const exe = b.addExecutable(.{
.name = "demo",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "c", .module = translate_c.createModule() }
}
}),
});
main.zig:
const c = @import("c");
pub fn main() void {
_ = c.printf("Hello, World!\n");
}
running zig build -fincremental run:
/home/bence/code/zig/demo/zig-out/bin/demo: symbol lookup error: /home/bence/code/zig/demo/zig-out/bin/demo: undefined symbol: main
run
└─ run exe demo failure
error: process exited with error code 127
failed command: /home/bence/code/zig/demo/zig-out/bin/demo
Build Summary: 4/6 steps succeeded (1 failed)
run transitive failure
└─ run exe demo failure
error: the following build command failed with exit code 1:
.zig-cache/o/3e62d5fd41c7b63ed3322b7f3ab3cc97/build /home/bence/.zvm/master/zig /home/bence/.zvm/master/lib /home/bence/code/zig/demo .zig-cache /home/bence/.cache/zig --seed 0x222d179b -Za8dc24b71f96b484 -fincremental run
This doesn't happen when translating c code without linking libc.
Expected Behavior
run without crash
### Zig Version
0.16.0, 0.17.0-dev.296+a85a29ae4
### Steps to Reproduce and Observed Behavior
- add an import using `b.addTranslateC` in build.zig
- set `link_libc` to true
- compile with -fincremental, and run the program
---
for example:
`lib.h`:
```
#include <stdio.h>
```
`build.zig`:
```
var translate_c = b.addTranslateC(.{
.root_source_file = b.path("src/lib.h"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
const exe = b.addExecutable(.{
.name = "demo",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "c", .module = translate_c.createModule() }
}
}),
});
```
`main.zig`:
```
const c = @import("c");
pub fn main() void {
_ = c.printf("Hello, World!\n");
}
```
running `zig build -fincremental run`:
```
/home/bence/code/zig/demo/zig-out/bin/demo: symbol lookup error: /home/bence/code/zig/demo/zig-out/bin/demo: undefined symbol: main
run
└─ run exe demo failure
error: process exited with error code 127
failed command: /home/bence/code/zig/demo/zig-out/bin/demo
Build Summary: 4/6 steps succeeded (1 failed)
run transitive failure
└─ run exe demo failure
error: the following build command failed with exit code 1:
.zig-cache/o/3e62d5fd41c7b63ed3322b7f3ab3cc97/build /home/bence/.zvm/master/zig /home/bence/.zvm/master/lib /home/bence/code/zig/demo .zig-cache /home/bence/.cache/zig --seed 0x222d179b -Za8dc24b71f96b484 -fincremental run
```
This doesn't happen when translating c code without linking libc.
### Expected Behavior
run without crash