chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] c++ example


From: David Dreisigmeyer
Subject: Re: [Chicken-users] c++ example
Date: Wed, 1 Dec 2010 10:13:18 -0500

This does work now.  Thank you for all the help!  I've included a
summary of everything below.

** punCpp.h:

void punCpp (void);

** punCpp.cpp:

#include <cstdio>
#include "punCpp.h"

using namespace std;

void punCpp (void)
{
  printf("Hello World!\n");
  return;
}

** pun_module.scm:

(module pun_module (test_pun)
        (import chicken scheme foreign)

        (foreign-declare "extern void punCpp (void);\n")
        
        (define pun_fun (foreign-lambda void "punCpp"))
        
        (define (test_pun)
          (pun_fun)))

** compile:

csc  -I/path/to/punCpp.h -C -m64 -c++ -s punCpp.cpp pun_module.scm

** run:

#;1> ,l pun_module.so
#;1> (import pun_module)
#;2> (test_pun)

On Wed, Dec 1, 2010 at 9:40 AM, David Dreisigmeyer
<address@hidden> wrote:
> Thanks Thomas and Peter.  I created a punCpp.h but forgot to include
> it on the email.  Let me try this on my end again.
>
> On Wed, Dec 1, 2010 at 9:30 AM, Peter Bex <address@hidden> wrote:
>> On Wed, Dec 01, 2010 at 08:23:40AM -0500, David Dreisigmeyer wrote:
>>> This may be getting closer.  Here's my code again (the names are
>>> slightly different from above):
>>
>> Here it complains about punCpp.h not being available.
>>
>> Simply making a file punCpp.h containing one line:
>>
>> void punCpp(void);
>>
>> caused the library to compile properly:
>>
>> #;1> (load "pun_module.so")
>> #;2> (import pun_module)
>> #;3> (test_pun)
>> Hello World!
>>
>> I'm on NetBSD/amd64, using Chicken 4.6.0 and gcc 4.1.3
>>
>> Cheers,
>> Peter
>> --
>> http://sjamaan.ath.cx
>> --
>> "The process of preparing programs for a digital computer
>>  is especially attractive, not only because it can be economically
>>  and scientifically rewarding, but also because it can be an aesthetic
>>  experience much like composing poetry or music."
>>                                                        -- Donald Knuth
>>
>> _______________________________________________
>> Chicken-users mailing list
>> address@hidden
>> http://lists.nongnu.org/mailman/listinfo/chicken-users
>>
>



reply via email to

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