Open messense opened 2 years ago
As seen in Homebrew/homebrew-core#95485, this can seemingly be fixed by installing Homebrew curl
and then passing the equivalent of --search-prefix "$(brew --prefix curl)"
to zig build
.
However, this isn't really a proper fix because, while the error about not being able to find the curl.h
error goes away, you then produce binaries that link with /usr/lib/libcurl.4.dylib
, which is strongly indicative of usage of Homebrew curl
headers but linkage with a non-Homebrew libcurl
.
@messense can you confirm this is still an issue with latest zig master?
@kubkon I am going to hijack this issue since it might at least be somewhat related.
I am encountering issues when using installHeadersDirectory
and installHeaders
where header files are not properly installed.
build.zig
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary(.{
.name = "zig-include-headers-repro",
.target = target,
.optimize = optimize,
});
lib.installHeader(b.path("headers/header.h"), "header.h");
lib.addCSourceFile(.{
.file = b.path("main.c"),
});
b.installArtifact(lib);
}
const std = @import("std");
main.c
#include "header.h"
#include <stdio.h>
int main()
{
printf("Hello %d", VERSION);
return 0;
}
headers/header.h
#define VERSION 20240514
zig build
produces the following stacktrace
yamashita@yamashitas-MacBook-Air> zig build
install
└─ install zig-include-headers-repro
└─ zig build-lib zig-include-headers-repro Debug native 1 errors
/Users/yamashita/Projects/zig-include-headers-repro/main.c:1:10: error: 'header.h' file not found
#include "header.h"
^~~~~~~~~~~
error: the following command failed with 1 compilation errors:
/nix/store/3x34axfakg6cwlzrj4nbc4mygwmaxn34-zig-0.13.0-dev.39+f6f7a47aa/bin/zig build-lib /Users/yamashita/Projects/zig-include-headers-repro/main.c -ODebug -Mroot --cache-dir /Users/yamashita/Projects/zig-include-headers-repro/zig-cache --global-cache-dir /Users/yamashita/.cache/zig --name zig-include-headers-repro -static --listen=-
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install zig-include-headers-repro transitive failure
└─ zig build-lib zig-include-headers-repro Debug native 1 errors
error: the following build command failed with exit code 1:
/Users/yamashita/Projects/zig-include-headers-repro/zig-cache/o/a162f7a33bd7f3dcdcd5696b1d6ca721/build /nix/store/3x34axfakg6cwlzrj4nbc4mygwmaxn34-zig-0.13.0-dev.39+f6f7a47aa/bin/zig /Users/yamashita/Projects/zig-include-headers-repro /Users/yamashita/Projects/zig-include-headers-repro/zig-cache /Users/yamashita/.cache/zig --seed 0x433abc0d -Z21d1e8ed1ec422ee
Running zig cc
produces the desired result:
yamashita@yamashitas-MacBook-Air> zig cc main.c -I./headers && ./a.out
Hello 20240514%
~You should be able to reproduce it using https://github.com/andrewrk/ffmpeg. Also relevant: https://github.com/andrewrk/ffmpeg/issues/14~.
EDIT: This was an oversight by me, PRCTL
and Metal
flags are not properly set in that repo for building on Darwin which was generating errors. Trying to build with appropriate flags fails with undefined reference to symbol
as observed here: https://github.com/andrewrk/ffmpeg/pull/11#issuecomment-1861013547.
Running macOS 14.4.1 (23E224)
on Apple M1
. Tested on 0.13.0-dev.39+f6f7a47aa
.
Zig Version
0.9.1
Steps to Reproduce
brew install --build-from-source zig
brew install --build-from-source fastfec
errorsHomebrew maintainer suggests we report issue here just in case it's a regression of zig.
Expected Behavior
Build successful.
Actual Behavior