ziglang/translate-c
17
128
Fork
You've already forked translate-c
37

#pragma once not respected when the same file is included twice via a non-canonical path #404

Closed
opened 2026年06月02日 03:46:41 +02:00 by johan0A · 1 comment

repro:

include/foo.h:

#pragma once
struct S { int x; };

build.zig:

conststd=@import("std");constTranslator=@import("translate_c").Translator;pubfnbuild(b:*std.Build)void{consttarget=b.standardTargetOptions(.{});constoptimize=b.standardOptimizeOption(.{});consttranslate_c_dep=b.dependency("translate_c",.{});consttranslate_c:Translator=.init(translate_c_dep,.{.c_source_file=b.addWriteFiles().add("stub.h",\\#include "foo.h"\\#include "../include/foo.h"),.target=target,.optimize=optimize,});translate_c.addIncludePath(b.path("include"));constout=b.addInstallFile(translate_c.output_file,"out.zig");b.getInstallStep().dependOn(&out.step);}

error produced:

install
└─ install generated to out.zig 
 └─ translate-c generated failure
C:\Users\johan\MyDocuments\git\nx\repro\include\../include/foo.h:2:8: error: redefinition of 'S'
struct S { int x; };
 ^
C:\Users\johan\MyDocuments\git\nx\repro\include\foo.h:2:8: note: previous definition is here 
struct S { int x; };
 ^

Expected

compiles successfully

## repro: `include/foo.h`: ```c #pragma once struct S { int x; }; ``` build.zig: ```zig const std = @import("std"); const Translator = @import("translate_c").Translator; pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const translate_c_dep = b.dependency("translate_c", .{}); const translate_c: Translator = .init(translate_c_dep, .{ .c_source_file = b.addWriteFiles().add("stub.h", \\#include "foo.h" \\#include "../include/foo.h" ), .target = target, .optimize = optimize, }); translate_c.addIncludePath(b.path("include")); const out = b.addInstallFile(translate_c.output_file, "out.zig"); b.getInstallStep().dependOn(&out.step); } ``` error produced: ``` install └─ install generated to out.zig └─ translate-c generated failure C:\Users\johan\MyDocuments\git\nx\repro\include\../include/foo.h:2:8: error: redefinition of 'S' struct S { int x; }; ^ C:\Users\johan\MyDocuments\git\nx\repro\include\foo.h:2:8: note: previous definition is here struct S { int x; }; ^ ``` ## Expected compiles successfully
Author
Copy link

nevermind, already fixed upstream: https://github.com/Vexu/arocc/issues/977

nevermind, already fixed upstream: https://github.com/Vexu/arocc/issues/977
Sign in to join this conversation.
No Branch/Tag specified
main
update
build-runner-process
zig-0.16.x
1.0.0
Labels
Clear labels
bounty
https://ziglang.org/news/announcing-donor-bounties
bug
Observed behavior contradicts documented or intended behavior.
contributor-friendly
This issue is limited in scope and/or knowledge of project internals.
downstream
An issue with a third-party project that uses this project.
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
infra
An issue related to project infrastructure, e.g. continuous integration.
optimization
A task to improve performance and/or resource usage.
question
No questions on the issue tracker; use a community space instead.
regression
Something that used to work in a previous version stopped working
upstream
An issue with a third-party project that this project uses.
use case
Describes a real use case that is difficult or impossible, but does not propose a solution.
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ziglang/translate-c#404
Reference in a new issue
ziglang/translate-c
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?