solve the mystery of undefined reference error

big surprise, C++ is to blame
master
Andrew Kelley 2016-01-15 17:12:26 -07:00
parent 8409e518ab
commit 8d60ffe314
3 changed files with 23 additions and 0 deletions

View File

@ -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.

View File

@ -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

View File

@ -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"
/*