Skip to content

Instantly share code, notes, and snippets.

@ncweinhold
Created May 25, 2011 20:44
Show Gist options
  • Save ncweinhold/991905 to your computer and use it in GitHub Desktop.
Save ncweinhold/991905 to your computer and use it in GitHub Desktop.
Calling Gambit-C scheme functions from C
#include <stdio.h>
#define ___VERSION 406001
#include "gambit.h"
#include "somescheme.h"
#define SCHEME_LIBRARY_LINKER ____20_somescheme__
___BEGIN_C_LINKAGE
extern ___mod_or_lnk SCHEME_LIBRARY_LINKER (___global_state_struct*);
___END_C_LINKAGE
int main(int argc, char** argv) {
printf("Hello World, this is from C\n");
___setup_params_struct setup_params;
___setup_params_reset (&setup_params);
setup_params.version = ___VERSION;
setup_params.linker = SCHEME_LIBRARY_LINKER;
___setup (&setup_params);
hello_from_scheme();
___cleanup();
return 0;
}
extern void hello_from_scheme(void);
(c-define (hello) () void "hello_from_scheme" "extern"
(write "Hello From Scheme")
(newline))
@feeley
Copy link

feeley commented Jul 18, 2021

Yes this is a "recent" (last year or two) change in the name of the linker function name.

@sonwh98
Copy link

sonwh98 commented Jul 18, 2021

I created more simple examples based on information provided here. Hopefully this will help others who find this gist
https://lambdakids.stigmergy.systems/2021/7/4/gambit-ffi.blog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment