metaeducation / rebol-ffi

FFI Extension For Ren-C
0 stars 0 forks source link

Unable to build with FFI on OS X #1

Open rgchris opened 6 years ago

rgchris commented 6 years ago

I'm trying to build on OS X (version 10.13.2).

I've installed the XCode Command Line Tools in order to create the /usr/include folder. The resultant folder contains ffi.h within an ffi subfolder (/usr/include/ffi/ffi.h).

On invoking make -f makefile.boot I eventually get the resultant output:

gcc -c -I../src/include -DREB_API -DENDIAN_LITTLE -DHAS_LL_CONSTS -DUSE_STRERROR_NOT_STRERROR_R -D_FILE_OFFSET_BITS=64 -DTO_OSX -DTO_OSX_X64 -O2 -fno-common -Wno-pointer-sign -o objs/ffi/ext-ffi.o ../src/extensions/ffi/ext-ffi.c
In file included from ../src/extensions/ffi/mod-ffi.c:36:
../src/extensions/ffi/reb-struct.h:31:10: fatal error: 'ffi.h' file not found
#include <ffi.h>
         ^~~~~~~
1 error generated.
make[1]: *** [objs/ffi/mod-ffi.o] Error 1
make[1]: *** Waiting for unfinished jobs....
In file included from ../src/extensions/ffi/t-struct.c:33:
../src/extensions/ffi/reb-struct.h:31:10: fatal error: 'ffi.h' file not found
#include <ffi.h>
         ^~~~~~~
In file included from ../src/extensions/ffi/t-routine.c:33:
../src/extensions/ffi/reb-struct.h:31:10: fatal error: 'ffi.h' file not found
#include <ffi.h>
         ^~~~~~~
1 error generated.
make[1]: *** [objs/ffi/t-struct.o] Error 1
1 error generated.
In file included from ../src/extensions/ffi/ext-ffi.c:40:
../src/extensions/ffi/reb-struct.h:31:10: fatal error: 'ffi.h' file not found
#include <ffi.h>
         ^~~~~~~
make[1]: *** [objs/ffi/t-routine.o] Error 1
1 error generated.
make[1]: *** [objs/ffi/ext-ffi.o] Error 1
1 warning generated.
make: *** [top] Error 2

I tried modifying the src/extensions/ffi/reb-struct.h file at line 31 to read:

#include <ffi/ffi.h>

With this result:

gcc -c -I../src/include -DREB_API -DENDIAN_LITTLE -DHAS_LL_CONSTS -DUSE_STRERROR_NOT_STRERROR_R -D_FILE_OFFSET_BITS=64 -DTO_OSX -DTO_OSX_X64 -O2 -fno-common -Wno-pointer-sign -o objs/ffi/ext-ffi.o ../src/extensions/ffi/ext-ffi.c
../src/extensions/ffi/mod-ffi.c:252:47: warning: implicit declaration of function 'ffi_closure_alloc' is invalid in C99
      [-Wimplicit-function-declaration]
    ffi_closure *closure = cast(ffi_closure*, ffi_closure_alloc(
                                              ^
../src/extensions/ffi/mod-ffi.c:252:28: warning: cast to 'ffi_closure *' (aka 'struct ffi_closure *') from smaller integer type 'int'
      [-Wint-to-pointer-cast]
    ffi_closure *closure = cast(ffi_closure*, ffi_closure_alloc(
                           ^
../src/include/reb-c.h:232:30: note: expanded from macro 'cast'
    #define cast(t,v)       ((t)(v))
                             ^
../src/extensions/ffi/mod-ffi.c:259:25: warning: implicit declaration of function 'ffi_prep_closure_loc' is invalid in C99
      [-Wimplicit-function-declaration]
    ffi_status status = ffi_prep_closure_loc(
                        ^
../src/extensions/ffi/t-routine.c:788:29: warning: implicit declaration of function 'ffi_prep_cif_var' is invalid in C99
      [-Wimplicit-function-declaration]
        ffi_status status = ffi_prep_cif_var( // "_var"-iadic prep_cif version
                            ^
../src/extensions/ffi/t-routine.c:872:5: warning: implicit declaration of function 'ffi_closure_free' is invalid in C99
      [-Wimplicit-function-declaration]
    ffi_closure_free(VAL_HANDLE_POINTER(ffi_closure, v));

And subsequently:

gcc -o r3 -fvisibility=hidden -rdynamic -framework CoreFoundation objs/a-constants.o objs/a-globals.o objs/a-lib.o objs/b-init.o objs/c-bind.o objs/c-do.o objs/c-context.o objs/c-error.o objs/c-eval.o objs/c-function.o objs/c-path.o objs/c-port.o objs/c-signal.o objs/c-value.o objs/c-word.o objs/d-crash.o objs/d-dump.o objs/d-eval.o objs/d-print.o objs/d-stack.o objs/d-stats.o objs/d-trace.o objs/f-blocks.o objs/f-deci.o objs/f-dtoa.o objs/f-enbase.o objs/f-extension.o objs/f-int.o objs/f-math.o objs/f-modify.o objs/f-qsort.o objs/f-random.o objs/f-round.o objs/f-series.o objs/f-stubs.o objs/l-scan.o objs/l-types.o objs/m-gc.o objs/m-pools.o objs/m-series.o objs/m-stacks.o objs/n-control.o objs/n-data.o objs/n-do.o objs/n-error.o objs/n-function.o objs/n-io.o objs/n-loop.o objs/n-math.o objs/n-native.o objs/n-protect.o objs/n-reduce.o objs/n-sets.o objs/n-strings.o objs/n-system.o objs/n-textcodecs.o objs/p-clipboard.o objs/p-console.o objs/p-dir.o objs/p-dns.o objs/p-event.o objs/p-file.o objs/p-net.o objs/p-serial.o objs/p-signal.o objs/s-cases.o objs/s-crc.o objs/s-file.o objs/s-find.o objs/s-make.o objs/s-mold.o objs/s-ops.o objs/s-trim.o objs/s-unicode.o objs/t-bitset.o objs/t-blank.o objs/t-block.o objs/t-char.o objs/t-datatype.o objs/t-date.o objs/t-decimal.o objs/t-event.o objs/t-function.o objs/t-gob.o objs/t-image.o objs/t-integer.o objs/t-library.o objs/t-logic.o objs/t-map.o objs/t-money.o objs/t-object.o objs/t-pair.o objs/t-port.o objs/t-string.o objs/t-time.o objs/t-tuple.o objs/t-typeset.o objs/t-varargs.o objs/t-vector.o objs/t-word.o objs/u-compress.o objs/u-md5.o objs/u-parse.o objs/u-sha1.o objs/u-zlib.o objs/tmp-boot-block.o objs/tmp-dispatchers.o objs/host-main.o objs/host-device.o objs/host-stdio.o objs/host-table.o objs/dev-net.o objs/dev-dns.o objs/generic/host-memory.o objs/generic/host-gob.o objs/posix/host-readline.o objs/posix/dev-stdio.o objs/posix/dev-event.o objs/posix/dev-file.o objs/posix/dev-serial.o objs/posix/host-browse.o objs/posix/host-config.o objs/posix/host-library.o objs/posix/host-process.o objs/posix/host-time.o objs/osx/host-exec-path.o objs/crypt/mod-crypt.o objs/crypt/aes/aes.o objs/crypt/bigint/bigint.o objs/crypt/dh/dh.o objs/crypt/rc4/rc4.o objs/crypt/rsa/rsa.o objs/crypt/sha256/sha256.o objs/crypt/ext-crypt.o objs/process/mod-process.o objs/process/ext-process.o objs/view/mod-view.o objs/view/ext-view.o objs/png/mod-lodepng.o objs/png/lodepng.o objs/png/ext-png.o objs/gif/mod-gif.o objs/gif/ext-gif.o objs/jpg/mod-jpg.o objs/jpg/u-jpg.o objs/jpg/ext-jpg.o objs/bmp/mod-bmp.o objs/bmp/ext-bmp.o objs/locale/mod-locale.o objs/locale/ext-locale.o objs/uuid/mod-uuid.o objs/uuid/ext-uuid.o objs/ffi/mod-ffi.o objs/ffi/t-struct.o objs/ffi/t-routine.o objs/ffi/ext-ffi.o objs/debugger/mod-debugger.o objs/debugger/ext-debugger.o -lm
Undefined symbols for architecture x86_64:
  "_ffi_call", referenced from:
      _Routine_Dispatcher in t-routine.o
  "_ffi_closure_alloc", referenced from:
      _N_wrap_callback in mod-ffi.o
  "_ffi_closure_free", referenced from:
      _cleanup_ffi_closure in t-routine.o
  "_ffi_prep_cif", referenced from:
      _Alloc_Ffi_Function_For_Spec in t-routine.o
  "_ffi_prep_cif_var", referenced from:
      _Routine_Dispatcher in t-routine.o
  "_ffi_prep_closure_loc", referenced from:
      _N_wrap_callback in mod-ffi.o
  "_ffi_type_double", referenced from:
      l_switch.table in t-struct.o
      l_switch.table in t-routine.o
  "_ffi_type_float", referenced from:
      l_switch.table in t-struct.o
      l_switch.table in t-routine.o
  "_ffi_type_pointer", referenced from:
      l_switch.table in t-struct.o
      l_switch.table in t-routine.o
  "_ffi_type_sint16", referenced from:
      l_switch.table in t-struct.o
      l_switch.table in t-routine.o
  "_ffi_type_sint32", referenced from:
      l_switch.table in t-struct.o
      l_switch.table in t-routine.o
  "_ffi_type_sint64", referenced from:
      l_switch.table in t-struct.o
      l_switch.table in t-routine.o
  "_ffi_type_sint8", referenced from:
      l_switch.table in t-struct.o
      l_switch.table in t-routine.o
  "_ffi_type_uint16", referenced from:
      l_switch.table in t-struct.o
      l_switch.table in t-routine.o
  "_ffi_type_uint32", referenced from:
      l_switch.table in t-struct.o
      l_switch.table in t-routine.o
  "_ffi_type_uint64", referenced from:
      l_switch.table in t-struct.o
      l_switch.table in t-routine.o
  "_ffi_type_uint8", referenced from:
      l_switch.table in t-struct.o
      l_switch.table in t-routine.o
  "_ffi_type_void", referenced from:
      _Routine_Dispatcher in t-routine.o
      _Alloc_Ffi_Function_For_Spec in t-routine.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [r3] Error 1
make: *** [top] Error 2

What to try next?

hostilefork commented 6 years ago

@zsx Has an FFI on mac build ever been done before?

@rgchris could you perhaps try getting basic support on StackOverflow for just building on Mac one of the ffi samples that uses closures?

http://www.chiark.greenend.org.uk/doc/libffi-dev/html/Closure-Example.html

There you can explain how you installed libffi (via brew) and what you've done.

rgchris commented 6 years ago

@hostilefork Q: How to include FFI in OS X?

I did download LibFFI via Brew but did not link it.

rgchris commented 6 years ago

Alas

hostilefork commented 6 years ago

Bad news: Mac OS indeed does not have the functions you are missing. Check out this, particularly Closure Allocation section. – user58697 2 hours ago

This is strange. @rgchris - while you can't build FFI now you have in the past, right? These calls aren't new...if you've ever built an R3 with FFI, you'd have had them.

Without those we'd have to #ifdef out two features: calling variadic functions (like printf) because it depends on ffi_prep_cif_var) and making callbacks...e.g. making it so that a Rebol function can be exposed as a C function. For an example of using callbacks, see:

https://github.com/metaeducation/ren-c/blob/master/tests/misc/qsort_r.r