From 8d60ffe314306e5295fb76338c6391e5fe986dea Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 15 Jan 2016 17:12:26 -0700 Subject: [PATCH] solve the mystery of undefined reference error big surprise, C++ is to blame --- README.md | 14 ++++++++++++++ src/config.h.in | 2 ++ src/zig_llvm.cpp | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 1b7ec0c9bd..b83eeeac5f 100644 --- a/README.md +++ b/README.md @@ -90,3 +90,17 @@ cmake .. -DCMAKE_BUILD_TYPE=Release -DZIG_LIBC_DIR=path/to/libc/dir make sudo make install ``` + +### Troubleshooting + +If you get one of these: + + * `undefined reference to `_ZNK4llvm17SubtargetFeatures9getStringB5cxx11Ev'` + * `undefined reference to `llvm::SubtargetFeatures::getString() const'` + +This is because of [C++'s Dual ABI](https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html). +Most likely LLVM was compiled with one compiler while Zig was compiled with a +different one, for example GCC vs clang. + +To fix this, compile Zig with the same compiler that LLVM was compiled with, or +add `-DZIG_LLVM_OLD_CXX_ABI=yes` to the cmake configure line. diff --git a/src/config.h.in b/src/config.h.in index c64c2b40f4..8b78e56238 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -10,4 +10,6 @@ #define ZIG_STD_DIR "@CMAKE_INSTALL_PREFIX@/@ZIG_STD_DEST@" #define ZIG_LIBC_DIR "@ZIG_LIBC_DIR@" +#cmakedefine ZIG_LLVM_OLD_CXX_ABI + #endif diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index 699963f5d3..be4cf2ac05 100644 --- a/src/zig_llvm.cpp +++ b/src/zig_llvm.cpp @@ -5,6 +5,13 @@ * See http://opensource.org/licenses/MIT */ +// This must go before all includes. +#include "config.h" +#if defined(ZIG_LLVM_OLD_CXX_ABI) +#define _GLIBCXX_USE_CXX11_ABI 0 +#endif + + #include "zig_llvm.hpp" /*