[LLVMdev] Kaleidoscope Build Error

Erick Tryzelaar idadesub at users.sourceforge.net
Fri Jun 10 22:27:25 PDT 2011


(cc'ing llvm-dev)

Hello Gregory,

i just recompiled llvm from scratch, and was able to build the ocaml
kaleidoscope bindings. Did you know the llvm's build system already
can compile the kaleidoscope tutorials for you? You can run this to
build them:

make BUILD_EXAMPLES=1

Or just cd into the examples directory in your build directory, and
run "make" there.

Anyway, I think the problem you're probably running into is that you
need to link with the ocaml "-cc g++" argument in order to link
against the c++ libraries, as in this:

/opt/local/bin/ocamlopt -cc g++ -pp camlp4of -I
/Users/erickt/Projects/llvm/gcc/llvm-build-Release/examples/OCaml-Kaleidoscope/Chapter7/Release+Asserts
-I /Users/erickt/Projects/llvm/gcc/llvm-build-Release/Release+Asserts/lib/ocaml
llvm.cmxa llvm_analysis.cmxa llvm_executionengine.cmxa
llvm_target.cmxa llvm_scalar_opts.cmxa -o
/Users/erickt/Projects/llvm/gcc/llvm-build-Release/examples/OCaml-Kaleidoscope/Chapter7/Release+Asserts/OCaml-Kaleidoscope-Ch7
/Users/erickt/Projects/llvm/gcc/llvm-build-Release/examples/OCaml-Kaleidoscope/Chapter7/Release+Asserts/ast.cmx
/Users/erickt/Projects/llvm/gcc/llvm-build-Release/examples/OCaml-Kaleidoscope/Chapter7/Release+Asserts/parser.cmx
/Users/erickt/Projects/llvm/gcc/llvm-build-Release/examples/OCaml-Kaleidoscope/Chapter7/Release+Asserts/codegen.cmx
/Users/erickt/Projects/llvm/gcc/llvm-build-Release/examples/OCaml-Kaleidoscope/Chapter7/Release+Asserts/lexer.cmx
/Users/erickt/Projects/llvm/gcc/llvm-build-Release/examples/OCaml-Kaleidoscope/Chapter7/Release+Asserts/token.cmx
/Users/erickt/Projects/llvm/gcc/llvm-build-Release/examples/OCaml-Kaleidoscope/Chapter7/Release+Asserts/toplevel.cmx
/Users/erickt/Projects/llvm/gcc/llvm-build-Release/examples/OCaml-Kaleidoscope/Chapter7/Release+Asserts/toy.cmx


Please let me know if that doesn't work for you.



On Fri, Jun 10, 2011 at 8:37 PM, Gregory Malecha <gmalecha at gmail.com> wrote:
> Hello Chris and Erick,
>
> I am very interested in using your llvm ocaml bindings, but I'm having some
> problems getting my code to link with it. I couldn't find a mailing list or
> anything like that to ask this question on. I've got a very simple main
> program:
>
> let load_bc ctx path =
>   Llvm_bitreader.parse_bitcode ctx (Llvm.MemoryBuffer.of_file path)
>
> let main () =
>   let ctx = Llvm.create_context () in
>   let m = load_bc ctx "examples/nweb/nweb.bc" in
>   print_string "loaded module successfully"
>
> and I'm trying to build it using this command (it's in a shell script to the
> variable declaration is actually working):
>
> D=/homes/malecha/tmp/llvm/lib
> /usr/bin/ocamlc -I ${D}/ocaml -cclib -lllvm -cclib -lllvm_bitwriter
> ${D}/ocaml/llvm.cma ${D}/ocaml/llvm_bitreader.cma ${D}/ocaml/libllvm.a
> src/main.ml -o main.native
>
> But I'm just getting a huge number of linker errors:
>
> File "src/main.ml", line 8, characters 6-7:
> Warning Y: unused variable m.
> /homes/malecha/tmp/llvm/lib/ocaml/libLLVMBitReader.a(BitReader.o): In
> function `LLVMParseBitcodeInContext':
> BitReader.cpp:(.text+0x19): undefined reference to `std::basic_string<char,
> std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage'
> BitReader.cpp:(.text+0xac): undefined reference to `std::basic_string<char,
> std::char_traits<char>, std::allocator<char>
>>::_Rep::_M_destroy(std::allocator<char> const&)'
> /homes/malecha/tmp/llvm/lib/ocaml/libLLVMBitReader.a(BitReader.o): In
> function `LLVMGetBitcodeModuleInContext':
> BitReader.cpp:(.text+0x139): undefined reference to `std::basic_string<char,
> std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage'
> BitReader.cpp:(.text+0x1cc): undefined reference to `std::basic_string<char,
> std::char_traits<char>, std::allocator<char>
>>::_Rep::_M_destroy(std::allocator<char> const&)'
> /homes/malecha/tmp/llvm/lib/ocaml/libLLVMBitReader.a(BitcodeReader.o): In
> function `llvm::BitcodeReader::MaterializeModule(llvm::Module*,
> std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)':
> BitcodeReader.cpp:(.text+0x1eb): undefined reference to `operator
> delete(void*)'
> /homes/malecha/tmp/llvm/lib/ocaml/libLLVMBitReader.a(BitcodeReader.o): In
> function `llvm::BitcodeReader::ResolveGlobalAndAliasInits()':
> BitcodeReader.cpp:(.text+0x48a): undefined reference to `operator
> delete(void*)'
> BitcodeReader.cpp:(.text+0x497): undefined reference to `operator
> delete(void*)'
> /homes/malecha/tmp/llvm/lib/ocaml/libLLVMBitReader.a(BitcodeReader.o): In
> function `llvm::BitcodeReader::FreeState()':
> BitcodeReader.cpp:(.text+0x884): undefined reference to `operator
> delete(void*)'
> BitcodeReader.cpp:(.text+0x96a): undefined reference to `operator
> delete(void*)'
> /homes/malecha/tmp/llvm/lib/ocaml/libLLVMBitReader.a(BitcodeReader.o):BitcodeReader.cpp:(.text+0x99c):
> more undefined references to `operator delete(void*)' follow
> /homes/malecha/tmp/llvm/lib/ocaml/libLLVMBitReader.a(BitcodeReader.o): In
> function `llvm::BitcodeReader::FreeState()':
> BitcodeReader.cpp:(.text+0xaed): undefined reference to `operator
> new(unsigned long)'
> ...
> /homes/malecha/tmp/llvm/lib/ocaml/libLLVMSupport.a(Allocator.o):(.data.rel.ro._ZTIN4llvm19MallocSlabAllocatorE[typeinfo
> for llvm::MallocSlabAllocator]+0x0): undefined reference to `vtable for
> __cxxabiv1::__si_class_type_info'
> /homes/malecha/tmp/llvm/lib/ocaml/libLLVMSupport.a(Allocator.o):(.data.rel.ro._ZTIN4llvm13SlabAllocatorE[typeinfo
> for llvm::SlabAllocator]+0x0): undefined reference to `vtable for
> __cxxabiv1::__class_type_info'
> /homes/malecha/tmp/llvm/lib/ocaml/libLLVMSupport.a(Errno.o): In function
> `llvm::sys::StrError(int)':
> Errno.cpp:(.text+0x49): undefined reference to `std::basic_string<char,
> std::char_traits<char>, std::allocator<char> >::basic_string(char const*,
> std::allocator<char> const&)'
> collect2: ld returned 1 exit status
> File "src/main.ml", line 1, characters 0-1:
> Error: Error while building custom runtime system
>
> I've tried a variety of build flags all to no avail. I've also tried
> ocamlbuild with the same results. Can either of you shed any light on this
> error?
>
> Thank you very much.
>
> --
> gregory malecha
>




More information about the llvm-dev mailing list