ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
33.78k stars 2.47k forks source link

zig cc - wrong include priority #9541

Open felixguendling opened 3 years ago

felixguendling commented 3 years ago

Hey! I wanted to use zig as a C++ and C compiler because of its ability to create statically linked binaries for all platforms. I ran into the issue that the syslog.h implementation of zig does not provide the defintiion of the syslog_data struct. Did anyone else run into this issue already and knows how to solve it? Am I doing something wrong?

libressl/crypto/cryptlib.c:348:21: error: variable has incomplete type 'struct syslog_data'
        struct syslog_data sdata = SYSLOG_DATA_INIT;
                           ^
libressl/crypto/cryptlib.c:348:9: note: forward declaration of 'struct syslog_data'
        struct syslog_data sdata = SYSLOG_DATA_INIT;
leecannon commented 3 years ago

As far as i can tell there is no syslog_data struct in glibc, musl nor mingw

Judging by a single google search it looks like it might be BSD only, are you building on BSD?

felixguendling commented 3 years ago

You're correct. Thank you.

However, I'm still not able to compile libressl using zig cc.

It seems like cryptlib.c makes #include <syslog.h> and it wants to include its own "syslog.h compatibility shim" where syslog_data and some other things are defined and #include_next <syslog.h> pulls the "real" syslog.h. What it gets is directly the official syslog.h. So for me it looks like zig cc is using the wrong include order. Or at least another include order than expected by libressl.

Maybe the project includes specified by -I don't have precedence against system includes which is different to how this is handled in "normal" compilers like GCC/mingw, Clang, MSVC (which are able to compile libressl)? I'm just guessing. Otherwise I would be quite clueless.

This happens with zig-linux-x86_64-0.8.0 as well as with zig-linux-x86_64-0.9.0-dev.749+259f3458a (the latest version linked on the download page).

I'm trying to write a toolchain file for CMake to compile my project (which relies on add_subproject(libressl)) using zig cc, zig c++, etc.

Edit: added an #error "syslog.h compatibility shim included" to the syslog.h compat shim from libressl and this never triggers. So I assume it's never actually used in the zig cc build. In other builds (normal GCC, Clang) the compilation is stopped with this error.