Can't load any egg when embedding Chicken Scheme library into C project

2

I'm working on a chicken library that I use in a C project. When I try to load eggs (e.g. (use intarweb)), the runtime complains about failing to load the egg.

(lldb) run
Error: (require) cannot load extension: intarweb

    Call history:

    bridge-connector.scm:6: ##sys#require       <--
Process 56172 exited with status = 70 (0x00000046)

I wondered whether the runtime failed to locate where the eggs are installed, so I tried setting CHICKEN_INCLUDE_PATH environment variable with no success:

export CHICKEN_INCLUDE_PATH="/usr/local/Cellar/chicken/4.13.0/lib/chicken/8/"

I even tried using load directly with the full path:

(load "/usr/local/Cellar/chicken/4.13.0/lib/chicken/8/intarweb.so")

but got the following error:

(lldb) run
Error: unbound variable: |\xcf\xfa\xed\xfe\x07\x00\x00\x01\x03\x00\x00\x00\x08\x00\x00\x00|

    Call history:

    bridge-connector.scm:6: load

I'm using Chicken Scheme 4 and I'm initializing the Chicken Scheme runtime as follow:

#include <chicken.h>

void my_lib_initialize()
{
  C_word k = CHICKEN_run(C_toplevel);
  (void)k;
}

My Chicken library is built as follow:

csc -embedded -debug-info -d3 -J -c bridge-connector.scm
csc -embedded -debug-info -d3 -c my-lib.scm
csc -c my_lib_initialize.c
csc ./my_lib_initialize.o ./my-lib.o ./bridge-connector.o -shared -embedded -static -debug-info -d3 -o libmy-lib.dylib
chicken-scheme
asked on Stack Overflow Oct 31, 2018 by Antoine

1 Answer

2

Don't use -static if you want to dynamically load extensions (which is what use does).

If you really want to link in intarweb statically, you'll have to compile it and all of its dependencies statically (which most CHICKEN 4 eggs don't currently do in their setup-file, so you must do it manually) and link them in, and use (declare (uses intarweb)) (import intarweb) instead of just (use intarweb). Here's a tutorial on how to do that. This is a bit involved in CHICKEN 4, unfortunately.

In CHICKEN 5, chicken-install has been rewritten to make it much easier to support static compilation of eggs. If you like, you can already try out the latest release candidate. Many eggs have already been ported (including intarweb) and it should be stable enough for usage; we expect this to be the last release candidate.

answered on Stack Overflow Oct 31, 2018 by sjamaan

User contributions licensed under CC BY-SA 3.0