[racket] FFI crashing Racket

From: Adriaan Leijnse (aleijnse at vub.ac.be)
Date: Fri Oct 10 12:38:19 EDT 2014

I'm trying to make use of Clang's C-API, but I might be missing
something in getting it to work with the FFI. Here's a C-program which
runs fine after compilation with "clang -o test test.c -lclang

#include <stdio.h>

typedef void *CXIndex;
extern CXIndex clang_createIndex(int, int);

int main() {
  clang_createIndex(0, 0);
  return 0;

However, running the following Racket program results in a crash
(probably a segfault but Racket just prints "aborted").

#lang racket

(require ffi/unsafe

(define libclang (ffi-lib "libclang"
                          #:global? #t
                          #:get-lib-dirs (λ _ '("/usr/lib/llvm-3.4/lib"))))

(define-ffi-definer defclang libclang)

(define _CXIndex (_cpointer _void))

(defclang clang_createIndex
  (_fun _int _int -> _CXIndex))

(clang_createIndex 0 0)

These programs look identical to me and I haven't had problems like
this using the FFI before, so I'm at a loss here. Any pointers?

Posted on the users mailing list.