[Top][All Lists]

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

Re: Guile, C++, and Mac OS X 10.4 (powerpc)

From: Hans Aberg
Subject: Re: Guile, C++, and Mac OS X 10.4 (powerpc)
Date: Wed, 28 Jul 2010 23:19:46 +0200

On 28 Jul 2010, at 21:49, Mike Solomon wrote:

Hey guile users,
   Trying to compile the simple example bessel.c from
Writing-Guile-Extensions.html (renamed because I'm using g+ +), I
encountered the following error: In function 'void init_bessel()': error: invalid conversion from 'scm_unused_struct*
(*)(scm_unused_struct*)' to 'scm_unused_struct* (*)(...)' error:   initializing argument 5 of 'scm_unused_struct*
scm_c_define_gsubr(const char*, int, int, int, scm_unused_struct* (*) (...))'

The SCM type is a pointer to an undefined C type - C hack, which clashes with C++. Clever in C, but bad for C++ users.

This even comes up when I put everything in extern "C" { ... }. I have seen other postings on the net for other software (lilypond, swig) that speaks of
the same issue, and some suggest that it is a problem with g++ and not
guile.  I'm using powerpc-apple-darwin8-g++-4.0.1 (GCC) 4.0.1 (Apple
Computer, Inc. build 5370)

When you use g++, all stuff is compiled as C++. So use gcc and add c++ libraries when linking.

Then in formally correct C++, main() must be C++. Gcc accepts calling C ++ from C, but attempting to pass an exception through a C function is converted to a termination exception.

So I wrote a C++ function scm::init_guile() calling scm_init_guile() and other stuff that needs to be initialized. Then
  int main(int argc, char** argv) {

    try {

Then write a header bessel.h

#ifndef BESSEL_H
#define BESSEL_H

/* Copyright ...
Free Software Foundation GNU General Public License < >

#ifdef __cplusplus
extern "C" {

void init_bessel();

#ifdef __cplusplus
} // extern "C"

#endif BESSEL_H

The file bessel.c is compiled as C, but your C++ files include bessel.h.


reply via email to

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