chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] c++ example


From: Alan Post
Subject: Re: [Chicken-users] c++ example
Date: Tue, 30 Nov 2010 22:53:57 -0700

On Tue, Nov 30, 2010 at 11:18:49AM -0500, David Dreisigmeyer wrote:
> Hi,
> 
> I was hoping to get some help with the c++ "hello world" example
> below.  I apologize for the question -- I'm currently learning both
> Chicken and C/C++ at the same time.  So far Chicken seems much easier
> than the other Lisps I've tried.  Thanks for the effort and great
> documentation on this implementation -- it's much appreciated.
> 
> -Dave
> 
> 
> If I do the following with C everything works out ok:
> 
> *pun.c:
> 
> #include <stdio.h>
> 
> void pun(void)
> {
>   printf ("To C, or not to C: that is the question.\n Or is it?\n");
> }
> 
> *pun_module.scm:
> 
> (module pun_module (test_pun)
>       (import chicken scheme foreign)
> 
>       (define pun_fun (foreign-lambda void "pun"))
>       
>       (define (test_pun)
>         (pun_fun)))
>       
> *compile:
> 
> gcc -c pun.c && csc-4.6.0 -s pun_module.scm pun.o
> 
> *at repl:
> 
> > ,l pun_module.so
> > (import pun_module)
> > (test_pun)
> 
> 
> ------------
> 
> When I try this:
> 
> *pun_cpp.cpp:
> 
> #include <iostream>
> using namespace std;
> 
> void pun_cpp (void)
> {
>   printf("Hello World!");
>   return;
> }
> 
> *pun_module.scm:
> 
> (module pun_module (test_pun)
>       (import chicken scheme foreign)
> 
>       (define pun_fun (foreign-lambda void "pun_cpp"))
>       
>       (define (test_pun)
>         (pun_fun)))
>       
> *compile:
> 
> g++ -c pun_cpp.cpp && csc-4.6.0 -s -c++ pun_module.scm pun_cpp.o
> 
> I get the following:
> 
> new-host:chicken daviddreisigmeyer$ g++ -c pun_cpp.cpp && csc-4.6.0 -s
> -c++ pun_module.scm pun_cpp.o
> pun_module.cpp: In function ‘long int stub6(long int)’:
> pun_module.cpp:29: error: ‘pun_cpp’ was not declared in this scope
> 
> Error: shell command terminated with non-zero exit status 256: g++
> pun_module.cpp -o pun_module.o -c -Wno-write-strings -no-cpp-precomp
> -fno-strict-aliasing -fwrapv -fno-common -DHAVE_CHICKEN_CONFIG_H -m64
> -DC_ENABLE_PTABLES -Os -fomit-frame-pointer -no-cpp-precomp -fPIC
> -DPIC -DC_SHARED
> -I"/Users/daviddreisigmeyer/Programming/scheme/chicken-4.6.0//include"
> 

I'm just guessing here, I don't know that much about FFI in chicken,
but I suspect you need to use:

extern "C" void pun_cpp (void)

when declaring a routine to be used from a C++ file by Chicken.
Otherwise the linker munges the name to support C++ function
overloading, and Chicken can't find it.

-Alan
-- 
.i ko djuno fi le do sevzi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]