neelance / ffi_gen

A generator for Ruby FFI bindings, directly from header files via LLVM's Clang compiler
MIT License
88 stars 26 forks source link

Documentation for getting started on OSX w/Hombrew? #40

Open michaeldauria opened 8 years ago

michaeldauria commented 8 years ago

I'm having trouble getting started using this tool on OSX:

LoadError: Could not open library 'libclang-3.5.so.1': dlopen(libclang-3.5.so.1, 5): image not found.
Could not open library 'libclang-3.5.so.1.dylib': dlopen(libclang-3.5.so.1.dylib, 5): image not found.
Could not open library 'libclang.so.1': dlopen(libclang.so.1, 5): image not found.
Could not open library 'libclang.so.1.dylib': dlopen(libclang.so.1.dylib, 5): image not found.
Could not open library 'clang': dlopen(clang, 5): image not found.
Could not open library 'libclang.dylib': dlopen(libclang.dylib, 5): image not found

I have installed llvm via: brew install llvm --with-clang on El Capitan, what am I missing?

skull-squadron commented 8 years ago

Try building LLVM like so:

brew uninstall llvm; brew install llvm \
  --with-all-targets \
  --with-python \
  --with-shared-libs

And then, this will probably be needed

( \
X="$(brew --prefix llvm)"; \
env PATH="$X/bin:$PATH" \
  DYLD_LIBRARY_PATH="$X/lib" \
  ruby your_ffi_gen_script.rb \
)

DO NOT RUN brew link llvm or it will break Xcode and your system

skull-squadron commented 8 years ago

Here's an example which works:

brew install nanomsg

( \
X="$(brew --prefix llvm)"; \
env PATH="$X/bin:$PATH" \
  DYLD_LIBRARY_PATH="$X/lib" \
  ruby -rffi_gen <<FFI_GEN_SCRIPT
inc = "#{\`brew --prefix nanomsg\`.chop}/include/"
FFIGen.generate(
  module_name: "Nanomsg",
  ffi_lib:     "nanomsg",
  headers:     Dir[inc+"**/*.h"].map {|x| x[inc.size..-1] },
  cflags:      \`llvm-config --cflags\`.split(" "),
  prefixes:    ["nanomsg", "NN_", "nn_"],
  output:      "nanomsg.rb",
)
FFI_GEN_SCRIPT
)