chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] c++ example


From: David Dreisigmeyer
Subject: [Chicken-users] c++ example
Date: Tue, 30 Nov 2010 11:18:49 -0500

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"



reply via email to

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