Created
May 25, 2011 20:44
-
-
Save ncweinhold/991905 to your computer and use it in GitHub Desktop.
Calling Gambit-C scheme functions from C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern void hello_from_scheme(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(c-define (hello) () void "hello_from_scheme" "extern" | |
(write "Hello From Scheme") | |
(newline)) |
Yes this is a "recent" (last year or two) change in the name of the linker function name.
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
#Thanks Marc!
the last line has this problem
it seems
somescheme_.c
defines
___LNK_somescheme__
line 8 in main.c has to replaced with that symbol instread of __20_somescheme
#define SCHEME_LIBRARY_LINKER _LNK_somescheme
This works now. Thanks again for your help