Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommended LLVM installation/configuration #31

Closed
ravinggenius opened this issue May 31, 2014 · 4 comments
Closed

Recommended LLVM installation/configuration #31

ravinggenius opened this issue May 31, 2014 · 4 comments

Comments

@ravinggenius
Copy link

I've been working on a new programming language, Rip, for a while now. I am able to construct the AST. I didn't know about RLTK before I got started, so I'm just trying to use RLTK to generated LLVM IR. I've compiled LLVM 3.5 from source based on the official instructions. The binaries and libraries are in a non-standard location (/Users/thomas/Code/llvm/build/Debug+Asserts/{bin,lib}) though.

Running RLTK::CG::Module.new('foo_module') results in the following error. What is the preferred way to install LLVM so I can use RLTK?

/usr/local/opt/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/ffi-1.9.3/lib/ffi/library.rb:133:in `block in ffi_lib': Could not open library 'LLVM-3.0': dlopen(LLVM-3.0, 5): image not found. (LoadError)
Could not open library 'libLLVM-3.0.dylib': dlopen(libLLVM-3.0.dylib, 5): image not found
    from /usr/local/opt/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/ffi-1.9.3/lib/ffi/library.rb:100:in `map'
    from /usr/local/opt/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/ffi-1.9.3/lib/ffi/library.rb:100:in `ffi_lib'
    from /usr/local/opt/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rltk-2.2.1/lib/rltk/cg/bindings.rb:46:in `<module:Bindings>'
    from /usr/local/opt/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rltk-2.2.1/lib/rltk/cg/bindings.rb:44:in `<module:CG>'
    from /usr/local/opt/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rltk-2.2.1/lib/rltk/cg/bindings.rb:23:in `<top (required)>'
    from /usr/local/opt/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rltk-2.2.1/lib/rltk/cg/module.rb:11:in `require'
    from /usr/local/opt/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rltk-2.2.1/lib/rltk/cg/module.rb:11:in `<top (required)>'
    from /Users/thomas/Code/rip-rip/lib/rip/nodes/module.rb:1:in `require'
    from /Users/thomas/Code/rip-rip/lib/rip/nodes/module.rb:1:in `<top (required)>'
    from /Users/thomas/Code/rip-rip/lib/rip/nodes.rb:28:in `require'
    from /Users/thomas/Code/rip-rip/lib/rip/nodes.rb:28:in `<top (required)>'
    from /Users/thomas/Code/rip-rip/lib/rip.rb:47:in `require'
    from /Users/thomas/Code/rip-rip/lib/rip.rb:47:in `<top (required)>'
    from ./bin/rip:3:in `require_relative'
    from ./bin/rip:3:in `<main>'
@chriswailes
Copy link
Owner

The problem here is that the LLVM shared library is not in the library path. To allow the OS to load your library you need to add it's location to the LD_LIBRARY_PATH environmental variable. It will then search that directory for the necessary .so file. You can add this in your ~/.bashrc file.

The second issue that you will run into is that RLTK requires a specific version of LLVM. At some point in the future it might be possible to allow it to use multiple different versions and enable/disable features based on which library it finds, but right now the RLTK trunk requires LLVM 3.4 (I plan on releasing a new Gem version based on trunk this weekend). Unless you have a very good reason for needing 3.5, I would recommend using 3.4 until LLVM 3.5 is released and RLTK is updated to use it. It will simplify your life considerably.

I hope that helps, and let me know if you have any further questions. If you don't mind me asking, what lexing/parsing libraries are you using?

@ravinggenius
Copy link
Author

I have LLVM trunk checked out to ~/Code/llvm. These are the exact steps I used to compile LLVM:

mkdir ~/Code/llvm
cd ~/Code/llvm
svn co http://llvm.org/svn/llvm-project/llvm/trunk .

cd tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd ..

cd projects
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
cd ..

mkdir build && cd build
../configure
mkdir ../bin # then i ran this, thinking it would reconfigure, but i don't think it did anything. `~/Code/llvm/bin` dir is empty
../configure --prefix=/Users/thomas/Code/llvm/bin

make
make check-all

I checked ~/Code/llvm/build/Debug+Asserts/bin and ~/Code/llvm/build/Debug+Asserts/lib, but neither directory has any *.so files. What directory needs to be set to $LD_LIBRARY_PATH?

I'm happy to recompile version 3.4, but shouldn't I be able to just $ brew install llvm? (By the way, that also doesn't work; see Homebrew/legacy-homebrew#29733.) If I do have to compile LLVM from source, should I checkout the source into my project or keep it separate? I've never done much with compiled languages, so I appreciate your help.

If you don't mind me asking, what lexing/parsing libraries are you using?

Don't mind at all. I'm using Parslet. It's pretty fantastic. Take a look at my parser or transformer if you'd like to see how I'm using it.

@ravinggenius
Copy link
Author

I remove LLVM and installed llvm34 via homebrew-version (as suggested by Homebrew/legacy-homebrew#29733). The version I got was 3.4.1, so all the binaries look like llvm-config-3.4.1.

What should I set $LD_LIBRARY_PATH to?

Can I configure something so it works with 3.4.1, or do I need to somehow install the 3.4 version?

@chriswailes
Copy link
Owner

So yes, I would recommend using pre-compiled packages. You'll need to make sure that the package includes the shared library (libLLVM3.4.so). Sometime these are separated out into another package, usually along the lines of llvm-libraries. Once you know where that library is located you can add it to LD_LIBRARY_PATH. Usually, if you are using a package manager it should be installed in a directory that is already in the standard search path for libraries.

Any release of LLVM in the 3.4 series will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants