bscarlet / llvm-general

Rich LLVM bindings for Haskell (with transfer of LLVM IR to and from C++, detailed compilation pass control, etc.)
http://hackage.haskell.org/package/llvm-general
132 stars 38 forks source link

Can't build on OS X El Capitan #193

Closed tibbe closed 8 years ago

tibbe commented 8 years ago

After installing LLVM 3.8 from Homebrew I try to compile the llvm-3.8-ghc-8 branch and get:

$ stack build
Cabal file warning in /Users/tibbe/src/ruin/llvm-general/llvm-general/llvm-general.cabal: Ignoring unknown section type: custom-setup
No packages found in snapshot which provide a "llvm-config" executable, which is a build-tool dependency of "llvm-general"
Missing build-tools may be caused by dependencies of the build-tool being overridden by extra-deps.
This should be fixed soon - see this issue https://github.com/commercialhaskell/stack/issues/595

llvm-general-pure-3.8.0.0: unregistering (flags changed from ["--extra-lib-dirs=/usr/local/Cellar/libffi/3.0.13/lib","--extra-lib-dirs=/usr/local/Cellar/llvm35/3.5.1/lib/llvm-3.5/lib"] to [])
llvm-general-pure-3.8.0.0: configure
llvm-general-pure-3.8.0.0: build
llvm-general-pure-3.8.0.0: copy/register
llvm-general-3.8.0.0: configure
llvm-general-3.8.0.0: build
Progress: 2/3
--  While building package llvm-general-3.8.0.0 using:
      /Users/tibbe/src/ruin/llvm-general/llvm-general/.stack-work/dist/x86_64-osx/Cabal-1.22.5.0/setup/setup --builddir=.stack-work/dist/x86_64-osx/Cabal-1.22.5.0 build lib:llvm-general --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
    Logs have been written to: /Users/tibbe/src/ruin/.stack-work/logs/llvm-general-3.8.0.0.log

    Warning: llvm-general.cabal: Ignoring unknown section type: custom-setup
    Configuring llvm-general-3.8.0.0...
    Warning: Instead of 'cc-options: -I/usr/local/Cellar/llvm/3.8.1/include' use
    'include-dirs: /usr/local/Cellar/llvm/3.8.1/include'
    Preprocessing library llvm-general-3.8.0.0...
    gcc: error: unrecognized command line option '-stdlib=libc++'
    gcc: error: unrecognized command line option '-Wcovered-switch-default'
    compiling .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/LLVM/General/Internal/LibraryFunction_hsc_make.c failed (exit code 1)
    command was: /Users/tibbe/bin/gcc -c .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/LLVM/General/Internal/LibraryFunction_hsc_make.c -o .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/LLVM/General/Internal/LibraryFunction_hsc_make.o -m64 -fno-stack-protector -D__GLASGOW_HASKELL__=710 -Ddarwin_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Ddarwin_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -Isrc -I/usr/local/Cellar/llvm/3.8.1/include -I/usr/local/Cellar/llvm/3.8.1/include -stdlib=libc++ -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -std=c++11 -DNDEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -I.stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/autogen -include .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/autogen/cabal_macros.h -I/usr/local/lib/ghc-7.10.3/bytes_6VWy06pWzJq9evDvK2d4w6/include -I/usr/local/lib/ghc-7.10.3/base_HQfYBxpPvuw8OunzQu6JGM/include -I/usr/local/lib/ghc-7.10.3/integ_2aU3IZNMF9a7mQ0OzsZ0dS/include -I/usr/local/lib/ghc-7.10.3/include -I/usr/local/lib/ghc-7.10.3/include/

(I'm using resolver: lts-6.20 for stack.)

Looks like we're passing an unknown flag to GCC.

P.S. It looks like the custom-setup section isn't recognized. Perhaps the cabal-version constraint needs to be bumped.

typedrat commented 8 years ago

It requires Cabal 1.24 from my experience.

tibbe commented 8 years ago

I've managed to build with cabal:

git clone https://github.com/bscarlet/llvm-general.git
cd llvm-general/
git checkout -b llvm-3.8 origin/llvm-3.8
cd llvm-general/
cabal sandbox init
cabal sandbox add-source ../llvm-general-pure/
cabal install --only-dep
cabal configure --extra-lib-dirs=/usr/local/Cellar/libffi/3.0.13/lib -v
cabal build

This is using GHC 7.10.3 and llvm38 from Homebrew.

tibbe commented 8 years ago

I spoke to soon. llvm-general itself can be built and installed but when linking my application I still get problems like these:

Undefined symbols for architecture x86_64:
  "llvm::TargetRegistry::lookupTarget(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, llvm::Triple&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)", referenced from:
      _LLVM_General_LookupTarget in libHSllvm-general-3.8.0.0-92hcfz1GLY9CjTAtL9qzyA.a(TargetC.o)
  "llvm::raw_fd_ostream::raw_fd_ostream(llvm::StringRef, std::error_code&, llvm::sys::fs::OpenFlags)", referenced from:
      _LLVM_General_WithFileRawOStream in libHSllvm-general-3.8.0.0-92hcfz1GLY9CjTAtL9qzyA.a(RawOStreamC.o)
  "llvm::Instruction::getAllMetadataImpl(llvm::SmallVectorImpl<std::pair<unsigned int, llvm::MDNode*> >&) const", referenced from:
      _LLVM_General_GetMetadata in libHSllvm-general-3.8.0.0-92hcfz1GLY9CjTAtL9qzyA.a(InstructionC.o)
  "std::__1::error_code::message() const", referenced from:
      _LLVMPrintModuleToFile in libLLVMCore.a(Core.o)
      _LLVMCreateMemoryBufferWithContentsOfFile in libLLVMCore.a(Core.o)
      _LLVMCreateMemoryBufferWithSTDIN in libLLVMCore.a(Core.o)
      llvm::Interpreter::create(std::__1::unique_ptr<llvm::Module, std::__1::default_delete<llvm::Module> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) in libLLVMInterpreter.a(Interpreter.o)
      llvm::getLazyIRFileModule(llvm::StringRef, llvm::SMDiagnostic&, llvm::LLVMContext&, bool) in libLLVMIRReader.a(IRReader.o)
      llvm::parseIR(llvm::MemoryBufferRef, llvm::SMDiagnostic&, llvm::LLVMContext&) in libLLVMIRReader.a(IRReader.o)
      llvm::parseIRFile(llvm::StringRef, llvm::SMDiagnostic&, llvm::LLVMContext&) in libLLVMIRReader.a(IRReader.o)
      ...
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::find(char, unsigned long) const", referenced from:
      llvm::Module::print(llvm::raw_ostream&, llvm::AssemblyAnnotationWriter*, bool, bool) const in libLLVMCore.a(AsmWriter.o)

I'm guessing the the application itself also needs to play games with extraLibs and ccOptions to make things link?

tibbe commented 8 years ago

It builds now. I had some other gcc on my path and removing that worked.

tibbe commented 7 years ago

Having to go through this again on a new machine I can confirm that building llvm-general works if you: