Skip to content

zig cc --sysroot=... does not work as expected for #includesΒ #19638

Closed as duplicate

Description

@alexrp

Zig Version

0.11.0

Steps to Reproduce and Observed Behavior

❯ echo "#include <test.h>" > test.c
❯ mkdir -p sys/usr/include
❯ touch sys/usr/include/test.h
❯ gcc --sysroot=$PWD/sys test.c -shared
❯ clang --sysroot=$PWD/sys test.c -shared
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: cannot find libgcc_s.so.1: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
❯ zig cc --sysroot=$PWD/sys test.c -shared
test.c:1:10: fatal error: 'test.h' file not found
#include <test.h>
         ^~~~~~~~
1 error generated.

(The linker errors when using non-Zig clang are irrelevant; the important point is that the #include works.)

Extra context:

❯ gcc --sysroot=$PWD/sys -E -Wp,-v - < /dev/null
ignoring nonexistent directory "/home/alexrp/Source/tests/sys/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/home/alexrp/Source/tests/sys/usr/local/include"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/include-fixed/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/home/alexrp/Source/tests/sys/usr/include/x86_64-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/13/include
 /home/alexrp/Source/tests/sys/usr/include
End of search list.
# 0 "<stdin>"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "<stdin>"
❯ clang --sysroot=$PWD/sys -E -Wp,-v - < /dev/null
clang -cc1 version 16.0.6 based upon LLVM 16.0.6 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/home/alexrp/Source/tests/sys/usr/local/include"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/home/alexrp/Source/tests/sys/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/llvm-16/lib/clang/16/include
 /home/alexrp/Source/tests/sys/usr/include
End of search list.
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 374 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
❯ zig cc --sysroot=$PWD/sys -E -Wp,-v - < /dev/null
clang -cc1 version 16.0.6 based upon LLVM 16.0.6 default target x86_64-linux-musl
ignoring nonexistent directory "/home/alexrp/Source/tests/sys/usr/local/include"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/home/alexrp/Source/tests/sys/include"
ignoring nonexistent directory "/opt/lib/clang/16/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/alexrp/Source/tests/sys/usr/include
End of search list.
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 375 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2

Expected Behavior

No preprocessor error.

Activity

  1. added
    bugObserved behavior contradicts documented or intended behavior
    on Apr 12, 2024
  2. alexrp commented on Apr 12, 2024

    @alexrp
    MemberAuthor

    I don't use this option frequently so it's entirely possible I'm just misunderstanding how it's meant to be used. From reading relevant man pages, it seems like this should work though.

  3. kassane commented on Apr 13, 2024

    @kassane
    Contributor

    Have you tried using -isystem for include?
    Does the same error occur on the master?

  4. alexrp commented on Apr 14, 2024

    @alexrp
    MemberAuthor

    Have you tried using -isystem for include?

    Yes, that's one way to work around it in my case, although it doesn't have the same general semantics.

    Does the same error occur on the master?

    Yes (0.12.0-dev.3644+05d975576).

  5. added this to the unplanned milestone on Aug 16, 2024
  6. alexrp commented on Jan 31, 2025

    @alexrp
    MemberAuthor

    Closing in favor of #22704.

  7. removed this from the unplanned milestone on Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorzig ccZig as a drop-in C compiler feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions