Commit 8d60ffe314

Andrew Kelley <superjoe30@gmail.com>
2016-01-16 01:12:26
solve the mystery of undefined reference error
big surprise, C++ is to blame
1 parent 8409e51
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
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"
 
 /*
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.