Open SpexGuy opened 4 years ago
The issue appears to be that we try to compile libcxxabi when using the MSVC c++ stdlib, I assume this is just wrong.
I don't think this is still an issue. @SpexGuy would you mind double checking that the error is now a linking error stating the lack of _WinMain
export? I actually would have expected _main
undefined rather than _WinMain
meaning we probably set subsystem to Windows by default rather than console.
This doesn't seem to be fixed, but some things have rearranged. Since we changed to the mingw abi by default, you need to use this command now to reproduce:
zig c++ -target native-native-msvc empty_file.cpp
We compile libc files in parallel now, so the error message is considerably harder to read as errors from many files are interleaved. I've attached the result of running this command: master_stderr.txt
OK, some success in at least narrowing this down. As far as I understood from LLVM's docs, they "guarantee" (or claim) that it is possible to build libcxx
lib with ucrt
and vcruntime
support (equivalent to compiling with msvc rather than clang), however, there is not much on building libcxxabi
as a replacement lib for msvc ABI. But, lemme talk some facts.
As far as I understood, ucrt
is the closest equivalent to libc on Windows while vcruntime
to libc++ with the former including the latter (yeah, they are very much intertwined). LLVM's libcxx
takes special care to respect that and it builds fine with Zig as the error brought up in this issue is actually about libcxxabi
. The error comes from the fact that clang complains about a mismatching forward declaration in cxxabi.h
within the LLVM's libcxxabi
which is
namespace std {
class type_info;
}
while being declared into the std
namespace in vcruntime_typeinfo.h
(part of vcruntime
lib) as
namespace std {
using ::type_info;
}
where it is also defined in the global scope. FWIW this actually should build fine with GCC, however, clang complains with an error
target of using declaration conflicts with declaration already in scope
using ::type_info;
This can be fixed with the following diff to the cxxabi.h
in libcxxabi
shipped with Zig:
diff --git a/lib/libcxxabi/include/cxxabi.h b/lib/libcxxabi/include/cxxabi.h
index 43ce6f5f7..c51579d77 100644
--- a/lib/libcxxabi/include/cxxabi.h
+++ b/lib/libcxxabi/include/cxxabi.h
@@ -25,12 +25,14 @@
#ifdef __cplusplus
-namespace std {
#if defined(_WIN32)
class _LIBCXXABI_TYPE_VIS type_info; // forward declaration
#else
class type_info; // forward declaration
#endif
+
+namespace std {
+ using ::type_info;
}
However, then we still hit a far more critical error
In file included from C:\Users\jk\dev\zig\build-release\lib\zig\libcxxabi\src/cxa_guard.cpp:15:
C:\Users\jk\dev\zig\build-release\lib\zig\libcxxabi\src/cxa_guard_impl.h:42:10: fatal error: 'unistd.h' file not found
#include <unistd.h>
^~~~~~~~~~
As you will know, unistd.h
is a header available on Posix systems which MS lacks (I think). And how to handle this, I think we'll need to have some discussion about next steps.
I just want to say even if you get past the missing unistd header you will then need to empty alot of of the cpp files because of re-declaration errors.
Dang, I am also stuck here. Seeing issues with exceptions and type_info as above when targeting msvc from ubuntu on 10.0-dev.3475, but compiles fine with gnu.
Not sure if this is useful, but I've had success with passing cpp files to zig build-exe
, and passing -lc
instead of -lc++
. At least some c++ std lib headers and objects are available with the msvc ABI and these settings.
On Windows,
zig c++ empty_file.cpp
fails with this error:The same error is observed when building
pub fn main() void {}
withzig build-exe -lc++
.Adding
--target=native-native-gnu
seems to fix it.