You are looking at historical revision 30202 of this page. It may differ significantly from its current revision.

Minimal example of embedding CHICKEN in a regular C program

From the Chicken-users mailing list, a post by Felix.

This shows a minimal example of embedding (you don't need CHICKEN_initialize, unless you want to set specific buffer sizes):

/* gcc x.c -lchicken -o x */

int main()
 C_word x;

 CHICKEN_eval_string("(print (+ 3 4))", &x);
 return 0;

Embedding CHICKEN in an Android application

A quick way to make sense of all the moving parts is to copy samples/hello-jni from your NDK directory.

Then you can alter hello-jni.c so it looks like this:

#include <string.h>
#include <jni.h>
#include <chicken.h>

Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
                                                  jobject thiz )
  C_word res;
  char foo[100];

  CHICKEN_eval_string("(+ 2 5)", &res);
  snprintf(foo, 100, "Evaluation result: %d", C_unfix(res));
  return (*env)->NewStringUTF(env, foo);

Then, build CHICKEN using PLATFORM=android for your target architecture (see the CHICKEN README for instructions). You'll have to build a for each architecture you want to support.

For simplicity, let's say for now that we only want to build for armeabi.

In your copy of the sample program, alter jni/ to read APP_ABI := armeabi. Copy to jni/chicken/armeabi and copy chicken.h to jni/chicken/include.

Then, create a file jni/chicken/ containing the following:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := chicken


Finally, add a line LOCAL_SHARED_LIBRARIES := chicken to jni/ and modify com/example/hellojni/ to load the chicken module before hello-jni is loaded:

    static {

You're all set!

To build, run /path/to/ndk/ndk-build and then ant debug to package up the program. You can

Extending this build to other ABI versions is simple: just add it to and build different versions and install them under the correspondingly named subdirectory under jni/chicken/<ABI-NAME>/