ffi: unknown type name 'size_t' on macOS 10.13.3

I’ve read every issue here that seemed only slightly related, but to no avail.

I’m unable to install ffi as compilation fails every time. I’m using macOS 10.13.3 and the following ruby version:

$ ruby -v
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]

$ gem -v
2.7.5

$ bundle -v
Bundler version 1.16.1

Ruby has been installed via Homebrew and resides in /usr/local/bin/ruby.

When I try to run sudo gem install ffi -v '1.9.18' or just sudo gem install ffi, I get the following error:

current directory: /usr/local/lib/ruby/gems/2.5.0/gems/ffi-1.9.18/ext/ffi_c
/usr/local/opt/ruby/bin/ruby -r ./siteconf20180207-9274-1xmicng.rb extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include,/usr/include/ffi... yes
checking for ffi_call() in -lffi... yes
checking for ffi_prep_closure()... yes
checking for ffi_raw_call()... no
checking for shlwapi.h... no
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_call_without_gvl()... yes
checking for ffi_prep_cif_var()... no
creating extconf.h
creating Makefile

current directory: /usr/local/lib/ruby/gems/2.5.0/gems/ffi-1.9.18/ext/ffi_c
make "DESTDIR=" clean

current directory: /usr/local/lib/ruby/gems/2.5.0/gems/ffi-1.9.18/ext/ffi_c
make "DESTDIR="
compiling AbstractMemory.c
compiling ArrayType.c
compiling Buffer.c
compiling Call.c
Call.c:355:5: warning: implicit declaration of function 'rb_thread_call_without_gvl' is invalid in C99 [-Wimplicit-function-declaration]
    rbffi_thread_blocking_region(call_blocking_function, data, (void *) -1, NULL);
    ^
./Thread.h:78:39: note: expanded from macro 'rbffi_thread_blocking_region'
# define rbffi_thread_blocking_region rb_thread_call_without_gvl
                                      ^
1 warning generated.
compiling ClosurePool.c
compiling DataConverter.c
compiling DynamicLibrary.c
compiling Function.c
Function.c:563:9: warning: implicit declaration of function 'rb_thread_call_without_gvl' is invalid in C99 [-Wimplicit-function-declaration]
        rb_thread_call_without_gvl(async_cb_wait, &w, async_cb_stop, &w);
        ^
1 warning generated.
compiling FunctionInfo.c
compiling LastError.c
compiling LongDouble.c
compiling MappedType.c
compiling MemoryPointer.c
compiling MethodHandle.c
compiling Platform.c
compiling Pointer.c
compiling Struct.c
compiling StructByReference.c
compiling StructByValue.c
compiling StructLayout.c
compiling Thread.c
In file included from Thread.c:38:
/usr/include/pthread.h:226:66: error: unknown type name 'size_t'
int pthread_attr_getguardsize(const pthread_attr_t * __restrict, size_t * __restrict);
                                                                 ^
/usr/include/pthread.h:243:43: error: unknown type name 'size_t'
                void * _Nullable * _Nonnull __restrict, size_t * __restrict);
                                                        ^
/usr/include/pthread.h:250:66: error: unknown type name 'size_t'
int pthread_attr_getstacksize(const pthread_attr_t * __restrict, size_t * __restrict);
                                                                 ^
/usr/include/pthread.h:511:1: error: unknown type name 'size_t'
size_t pthread_get_stacksize_np(pthread_t);
^
4 errors generated.
make: *** [Thread.o] Error 1

make failed, exit code 2

This happens with both built-in GCC 4.2 and 7.3 installed via Homebrew.

I know that this might be a setup issue more than a problem with the library, but any help is greatly appreciated.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 7
  • Comments: 15 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Please expedite this fix! Ruby on Rails on Mac is effectively dead until you do.

I’m using macOS 10.13.3 + XCode9.3 beta2 and solved the problem unknown type name 'size_t' by following steps.

  1. follow the official instructions and checkout the code.
  2. add stddef.h to Thread.c
diff --git a/ext/ffi_c/Thread.c b/ext/ffi_c/Thread.c
index 32ae05f..e85ea40 100644
--- a/ext/ffi_c/Thread.c
+++ b/ext/ffi_c/Thread.c
@@ -27,6 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <stddef.h>
 #ifndef _MSC_VER
 #include <stdbool.h>
 #else
  1. rake install

Hope this helps.