Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building Zig + C projects fail on macOS #6773

Closed
prime31 opened this issue Oct 23, 2020 · 4 comments · Fixed by #6791
Closed

Building Zig + C projects fail on macOS #6773

prime31 opened this issue Oct 23, 2020 · 4 comments · Fixed by #6791
Labels
bug Observed behavior contradicts documented or intended behavior os-macos
Milestone

Comments

@prime31
Copy link
Contributor

prime31 commented Oct 23, 2020

The main issue seems to be a regression in Zig's ability to build and link c/c++ code. A few months back there was a change made to zig that I haven't yet pin-pointed. Since that time Zig has been unable to build an executable in a project with C++ code in it (C still worked at that time). Using today's master, neither C nor C++ code in a Zig project will build.

Some Example projects with Zig and C/C++ code that work with previous versions of Zig (0.6.0+68bf29c31 is the last working version I have available):
https://github.com/floooh/sokol-zig
https://github.com/prime31/zig-upaya
https://github.com/prime31/zig-miniaudio

The errors are generally the same for all projects. Here is one example:

error(compilation): clang failed with stderr: In file included from zig-master/build/lib/zig/libcxx/src/algorithm.cpp:9:
In file included from zig-master/build/lib/zig/libcxx/include/algorithm:643:
In file included from zig-master/build/lib/zig/libcxx/include/memory:681:
In file included from zig-master/build/lib/zig/libcxx/include/atomic:571:
In file included from zig-master/build/lib/zig/libcxx/include/__threading_support:27:
In file included from zig-master/build/lib/zig/libc/include/generic-glibc/pthread.h:22:
In file included from zig-master/build/lib/zig/libc/include/generic-glibc/sched.h:25:
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:139:3: error: 
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:145:1: error: unknown type name '__STD_TYPE'
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:145:24: error: expected ';' after top level declarator
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:146:1: error: unknown type name '__STD_TYPE'
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:147:1: error: unknown type name '__STD_TYPE'
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:148:1: error: unknown type name '__STD_TYPE'
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:149:1: error: unknown type name '__STD_TYPE'
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:149:26: error: expected ';' after top level declarator
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:150:1: error: unknown type name '__STD_TYPE'
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:151:1: error: unknown type name '__STD_TYPE'
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:151:26: error: expected ';' after top level declarator
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:152:1: error: unknown type name '__STD_TYPE'
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:153:1: error: unknown type name '__STD_TYPE'
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:153:26: error: expected ';' after top level declarator
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:154:1: error: unknown type name '__STD_TYPE'
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:155:1: error: unknown type name '__STD_TYPE'
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:156:1: error: unknown type name '__STD_TYPE'
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:157:1: error: unknown type name '__STD_TYPE'
zig-master/build/lib/zig/libc/include/generic-glibc/bits/types.h:158:1: error: unknown type name '__STD_TYPE'
fatal error: too many errors emitted, stopping now [-ferror-limit=]


... many of these for 40 or so files in zig/libcxx/src

error(compilation): zig-master/build/lib/zig/libcxx/src/algorithm.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/any.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/atomic.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/barrier.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/bind.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/chrono.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/condition_variable.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/condition_variable_destructor.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/debug.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/experimental/memory_resource.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/filesystem/directory_iterator.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/filesystem/operations.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/functional.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/future.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/hash.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/ios.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/iostream.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/locale.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/memory.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/mutex.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/mutex_destructor.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/new.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/optional.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/random.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/random_shuffle.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/regex.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/shared_mutex.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/stdexcept.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/string.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/strstream.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/system_error.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/thread.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/valarray.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/variant.cpp:1:1: unable to build C object: clang exited with code 1
error(compilation): zig-master/build/lib/zig/libcxx/src/vector.cpp:1:1: unable to build C object: clang exited with code 1
error: unable to build libcxx: BuildingLibCObjectFailed
@kubkon
Copy link
Member

kubkon commented Oct 24, 2020

Thanks for the report @prime31! It is indeed a regression in the compiler that I have introduced when I added libc headers on macOS. #6791 should fix this issue though.

@prime31
Copy link
Contributor Author

prime31 commented Oct 24, 2020

Excellent, thanks @kubkon! Your PR seems to fix C compilation but C++ compilation still fails with just Segmentation fault: 11.

You can reproduce by just testing on this repo (https://github.com/prime31/zig-upaya) that has C code (Sokol) and C++ (Dear ImGui) mixed with the zig. I made a branch that is updated to be compatible with Zig master as of today. Repro steps:

git clone --recursive https://github.com/prime31/zig-upaya
cd zig-upaya
git checkout zig-master-10-24
zig build

@kubkon
Copy link
Member

kubkon commented Oct 25, 2020

Thanks for the report @prime31! Would you mind opening a new issue specifically for your C++ issue?

@prime31
Copy link
Contributor Author

prime31 commented Oct 25, 2020

Thanks for the report @prime31! Would you mind opening a new issue specifically for your C++ issue?

Done deal! #6812 created.

@andrewrk andrewrk added this to the 0.7.0 milestone Oct 26, 2020
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior os-macos labels Oct 26, 2020
andrewrk added a commit that referenced this issue Nov 9, 2020
This is an alternate fix for #6773. Reverts
872bc78.
andrewrk added a commit that referenced this issue Nov 9, 2020
This is an alternate fix for #6773. Reverts
872bc78.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior os-macos
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants