Skip to content

zig build-exe can't find headers/libraries when search paths cross a symbolic link #10173

@lukekras

Description

@lukekras

Remember to search before filing a new report

  • I searched for this bug and did not find it in the issue tracker, and furthermore, the title I used above will make this new bug report turn up in the search results for my query.

Zig Version

0.9.0-dev.1679+6cf8a49bb

Steps to Reproduce

This problem can be reproduced by building and executing C interoperability example. The problem was observed on a MacBook Pro MacOS Big Sur (Intel). zig build-exe doesn't seem to be able to search system include paths across symbolic links. When using a package manager like Homebrew, it only uses symbolic links to separate Homebrew installations and build directories from the system search paths, while avoiding the need for Superuser privileges for installing software.

Using Homebrew install raylib and zig.
brew install --HEAD zig
brew install --HEAD raylib

This should build hello-raylib executable, but it doesn't.
zig build-exe --library raylib hello-raylib.zig

With Homebrew, raylib headers would be searched for in /usr/local/include. The headers are really symbolically linked to a Cellar directory e.g. /usr/local/include/raylib.h -> ../Cellar/raylib/HEAD-3a9f089/include/raylib.h, which is different for each version. In this case the version is the master HEAD at commit point 3a9f089.

If you specify a zip build-exe by adding the actual header and library locations (thus avoiding travelling over symbolic links), it builds.
zig build-exe -I/usr/local/Cellar/raylib/HEAD-3a9f089/include -L/usr/local/Cellar/raylib/HEAD-3a9f089/lib --library raylib hello-raylib.zig

This problem doesn't happen when using the zig build command either.

Attached is the raylib hello world code. I've added a .txt because github doesn't support uploading zig files in issues.
hello-raylib.zig.txt

Expected Behavior

I expected a zig-cache directory and a hello-raylib executable. When the executable is run, a basic window pops up with Hello World!

Screen Shot 2021-11-19 at 11 58 23 pm

Actual Behavior

zig build-exe --library raylib hello-raylib.zig
./hello-raylib.zig:1:13: error: C import failed
const ray = @cImport({
            ^
zig-cache/o/f1f056f0c5fb85b4fa0abc416fd3c51d/cimport.h:1:10: note: 'raylib.h' file not found
#include <raylib.h>
         ^
./hello-raylib.zig:9:5: note: referenced here
    ray.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions