ffi_gen icon indicating copy to clipboard operation
ffi_gen copied to clipboard

Documentation for getting started on OSX w/Hombrew?

Open michaeldauria opened this issue 9 years ago • 2 comments

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?

michaeldauria avatar Feb 07 '16 18:02 michaeldauria

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 avatar Aug 23 '16 07:08 skull-squadron

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
)

skull-squadron avatar Aug 23 '16 10:08 skull-squadron