Skip to content

Aro translate-c can't find system includes #23015

Open
@BratishkaErik

Description

@BratishkaErik

Zig Version

0.14.0-dev.3388+e0a955afb

Steps to Reproduce and Observed Behavior

Add following C file as main.c:

#include <stdio.h>

int main() {
    fprintf(stdout, "Hello world!\n");
    return 0;
}

Run zig translate-c -fno-clang -cflags -I /usr/include/ -- main.c:

main.c:1:10: fatal error: 'stdio.h' not found
#include <stdio.h>
         ^
error: the following build command failed with exit code 1:
/home/bratishkaerik/.cache/zig/o/5e1450512c6df0efd9f90b6dbc27bb9b/aro_translate_c main.c

Alternatively, use zig build to translate it:

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const translate = b.addTranslateC(.{
        .root_source_file = b.path("main.c"),
        .target = target,
        .optimize = optimize,
        .use_clang = false,
    });
    b.getInstallStep().dependOn(&translate.step);
}
install
└─ translate-c failure
error: /home/bratishkaerik/test/zig/arocc-translate-c/main.c:1:10: fatal error: 'stdio.h' not found
#include <stdio.h>
         ^
error: the following build command failed with exit code 1:
/home/bratishkaerik/.cache/zig/o/5e1450512c6df0efd9f90b6dbc27bb9b/aro_translate_c /home/bratishkaerik/test/zig/arocc-translate-c/main.c

error: the following command exited with error code 1:
/usr/lib64/zig/9999/bin/zig translate-c -lc -fno-clang --listen=- /home/bratishkaerik/test/zig/arocc-translate-c/main.c 
Build Summary: 0/2 steps succeeded; 1 failed
install transitive failure
└─ translate-c failure
error: the following build command failed with exit code 1:
/home/bratishkaerik/test/zig/arocc-translate-c/.zig-cache/o/63bdfecf200b727a458229346199793a/build /usr/lib64/zig/9999/bin/zig /usr/lib64/zig/9999/lib /home/bratishkaerik/test/zig/arocc-translate-c /home/bratishkaerik/test/zig/arocc-translate-c/.zig-cache /home/bratishkaerik/.cache/zig --seed 0xe3a7d3d0 -Z1dc1d5cdcd58ae84

Checked on Gentoo and Debian.

Expected Behavior

To work fine and find system includes as with Clang frontend:

$ zig translate-c -fclang -cflags -I /usr/include/ -- main.c
// a lot of output...

$ zig build
// works fine with `.use_clang = true`

Or like arocc in compiler mode:

$ arocc main.c
// a lot of warnings, but at least it sees headers
51 warnings generated.
fatal error: TODO CodeGen.genVar

1 error generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviortranslate-cC to Zig source translation feature (@cImport)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions