Focus on IT Recommend

Home > dll - How do you build Rebol's "Ren-C" branch with LibFFI support?

dll - How do you build Rebol's "Ren-C" branch with LibFFI support?



I'd like to access a dynamic library using FFI features in the Ren-C Rebol branch. I understand this is possible by building with LibFFI support enabled. What steps do I need to take to enable this?

I mainly use OS X for development, though would also like to be able to build it for use with Linux.

dll rebol rebol3
edited Jan 10 '16 at 21:51 HostileFork 21.5k 6 56 109 asked Jan 10 '16 at 20:26 rgchris 2,134 10 17


2 Answers


(Note: This is probably the kind of information that should be added to the Wiki, as it is not so much a language question but the kind of thing that is subject to change over time. But, answerable, so...)

If you're using the GNU make method to build (where make -f makefile.boot generates a makefile for you) then you should find some lines in there like:

OS_ID?= 0.2.40

Modify the RAPI_FLAGS and HOST_FLAGS lines at the beginning to add -DHAVE_LIBFFI_AVAILABLE. That (-D)efines a preprocessor directive to tell the code it's okay to generate calls to FFI, because you have it available for linking later.

Now to tell it where to find include files. There's a line for includes that should look like:

INCL ?= .
I= -I$(INCL) -I$S/include/ -I$S/codecs/ ...

To the tail of that you need to add something that will look like -I/usr/local/opt/libffi/lib/libffi-3.0.13/include, or similar. The actual directory will depend on where you have libffi on your system. On the OSX system I'm looking at, that has two files in it, ffi.h and ffitarget.h.

(Note: I'm afraid I don't know how these files got on this computer. They didn't ship with the OS, so they came from...somewhere. I don't generally develop on OSX--nor for that matter do I use this FFI. You'll have to consult your local FFI-on-OSX website, or perhaps for support contact Atronix Engineering) who added the FFI features to Rebol.)

Then it's necessary to tell it where you have libffi on your system. You'll find a CLIB line that is likely just CLIB= -lm. You'd change this for example to:

CLIB= -L/usr/local/opt/libffi/lib -lm -lffi

-lffi Tells it to look for the ffi (-l)ibrary, and -lxxx means it assumes the name of the library will be libxxx[something]. -L/usr/local/opt/libffi/lib tells it where to look for it. You'll have to figure out where (if anywhere) you have libffi, and if not get it. If you had it, the directory would have contents something like:


I mainly use OS X for development, though would also like to be able to build it for use with Linux.

On Linux it's similar but generally much easier to get the library, as easy as sudo apt-get install libffi-dev. Same step for the RFLAGS and CFLAGS, and it should take care of the location automatically... so you can add just -lffi to CLIB.

edited Jan 11 '16 at 1:50 answered Jan 10 '16 at 21:01 HostileFork 21.5k 6 56 109      I've made the changes to the generated makefile—how do I invoke it? –  rgchris Jan 11 '16 at 1:16      Ok— make seems to work. Not yet able to create a routine yet: 'This Rebol build wasn't linked with libffi features' –  rgchris Jan 11 '16 at 1:36      Per chat: make clean then make. –  rgchris Jan 11 '16 at 3:21      ^^ chat reference –  rgchris Jan 11 '16 at 3:34


Old notes from me:

cat steps-for-lib-ffi-osx

Install libfffi via homebrew

brew install libffi

Add /use/include/libffi to the -I in the generated makefile

Add /usr/local/Cellar/libffi/3.0.13/lib/libffi.a to the OBJS in the generated makefile

The version 3.0.13 may vary

answered Jan 17 '16 at 12:37 Maarten 62 1 6      I used a Yosemite box to build in this case so Fork's recipe worked for me. I'm not certain which version of OS X was the first to include LibFFI though. –  rgchris Jan 17 '16 at 15:43



------splitte line----------------------------