[Haskell-cafe] undefined reference to '__gxx_personality_v0'
Moritz Kiefer
moritz.kiefer at purelyfunctional.org
Mon Aug 28 10:23:09 UTC 2017
Hey Henning,
Try linking against `libstdc++` by adding it to `extra-libraries`. If
you care about cross-plattform compatiblity you will also need to make
sure that you use the same C++ stdlib that LLVM was linked against (e.g.
on macOS it’s libc++). `llvm-config --cxxflags` should help with that.
Moritz
On 08/28/2017 08:31 AM, Henning Thielemann wrote:
>
> 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.
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170828/8291219b/attachment.sig>
More information about the Haskell-Cafe
mailing list