[Haskell-cafe] undefined reference to '__gxx_personality_v0'

Henning Thielemann lemming at henning-thielemann.de
Mon Aug 28 06:31:51 UTC 2017


I have trouble to compile my llvm-ffi package containing C++ binding code. 
I am on Ubuntu 16.04 and I have created a custom llvm.pc file:

$ cat /usr/local/lib/pkgconfig/llvm-3.8.pc
Name: LLVM
Description: Low-level Virtual Machine compiler framework
Version: 3.8.0
URL: http://www.llvm.org/
Requires:
Conflicts:
Libs: -L/usr/lib/llvm-3.8/lib -lLLVM-3.8.0
Cflags: -I/usr/lib/llvm-3.8/include -std=c++0x -std=c++11

/tmp$ cabal unpack llvm-ffi
Unpacking to llvm-ffi-3.8.1/
/tmp$ cd llvm-ffi-3.8.1/
/tmp/llvm-ffi-3.8.1$ cabal configure -fbuildExamples --with-ghc=ghc-8.2.1
Resolving dependencies...
Configuring llvm-ffi-3.8.1...
/tmp/llvm-ffi-3.8.1$ cabal build
Preprocessing library for llvm-ffi-3.8.1..
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
Building library for llvm-ffi-3.8.1..
[ 1 of 22] Compiling LLVM.FFI.Core    ( dist/build/LLVM/FFI/Core.hs, dist/build/LLVM/FFI/Core.o )
[ 2 of 22] Compiling LLVM.FFI.BitWriter ( src/LLVM/FFI/BitWriter.hs, dist/build/LLVM/FFI/BitWriter.o )
[ 3 of 22] Compiling LLVM.FFI.BitReader ( src/LLVM/FFI/BitReader.hs, dist/build/LLVM/FFI/BitReader.o )
[ 4 of 22] Compiling LLVM.FFI.Analysis ( src/LLVM/FFI/Analysis.hs, dist/build/LLVM/FFI/Analysis.o )
...
Preprocessing executable 'llvm-ffi-example' for llvm-ffi-3.8.1..
Building executable 'llvm-ffi-example' for llvm-ffi-3.8.1..
[1 of 1] Compiling Main             ( example/JIT.hs, 
dist/build/llvm-ffi-example/llvm-ffi-example-tmp/Main.o )
Linking dist/build/llvm-ffi-example/llvm-ffi-example ...
/tmp/llvm-ffi-3.8.1/dist/build/libHSllvm-ffi-3.8.1-KKUvbYcVYVe5ZjJKumuzkS.a(support.o):support.cpp:function 
LLVMGetHostFeatures: error: undefined reference to 'operator new(unsigned 
long)'
/tmp/llvm-ffi-3.8.1/dist/build/libHSllvm-ffi-3.8.1-KKUvbYcVYVe5ZjJKumuzkS.a(support.o):support.cpp:function 
LLVMGetHostFeatures: error: undefined reference to 'operator 
delete(void*)'
/tmp/llvm-ffi-3.8.1/dist/build/libHSllvm-ffi-3.8.1-KKUvbYcVYVe5ZjJKumuzkS.a(support.o):support.cpp:function 
LLVMCheckFeature(llvm::StringMap<bool, llvm::MallocAllocator>*, 
llvm::StringMapConstIterator<bool>*): error: undefined reference to 
'operator delete(void*)'
/tmp/llvm-ffi-3.8.1/dist/build/libHSllvm-ffi-3.8.1-KKUvbYcVYVe5ZjJKumuzkS.a(support.o):support.cpp:function 
LLVMGetFirstFeature: error: undefined reference to 'operator new(unsigned 
long)'
/tmp/llvm-ffi-3.8.1/dist/build/libHSllvm-ffi-3.8.1-KKUvbYcVYVe5ZjJKumuzkS.a(support.o):support.cpp:function 
LLVMCreateExecutionEngineKindForModuleCPU: error: undefined reference to 
'operator delete(void*)'
/tmp/llvm-ffi-3.8.1/dist/build/libHSllvm-ffi-3.8.1-KKUvbYcVYVe5ZjJKumuzkS.a(support.o):support.cpp:function 
LLVMCreateExecutionEngineKindForModuleCPU: error: undefined reference to 
'std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> >::_M_replace(unsigned long, unsigned long, char 
const*, unsigned long)'
/tmp/llvm-ffi-3.8.1/dist/build/libHSllvm-ffi-3.8.1-KKUvbYcVYVe5ZjJKumuzkS.a(support.o):support.cpp:function 
LLVMCreateExecutionEngineKindForModuleCPU: error: undefined reference to 
'operator delete(void*)'
/tmp/llvm-ffi-3.8.1/dist/build/libHSllvm-ffi-3.8.1-KKUvbYcVYVe5ZjJKumuzkS.a(support.o):support.cpp:DW.ref.__gxx_personality_v0: 
error: undefined reference to '__gxx_personality_v0'
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)


StackOverflow discussions on those linker errors suggest that it is 
important to link with g++, not gcc. Can I control how GHC links?

How do other packages cope with C++ code? It seems that they most oftenly 
come with custom Setup modules that cause trouble with different Cabal 
versions. I hoped that I can prevent those difficulties using pkg-config. 
Unfortunately, pkg-config seems to be limited to C libraries. Thus the 
warnings about the -std=c++11 option in the beginning.

Maybe it is cleaner to write a separate LLVM C package that interfaces to 
the C++ code and bind Haskell to C via pkg-config. However, it would mean 
that I have to maintain a C library for Linux, Mac and Windows with 
autoconf et.al.


More information about the Haskell-Cafe mailing list