From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Hans Aberg Newsgroups: gmane.lisp.guile.user Subject: Re: Guile, C++, and Mac OS X 10.4 (powerpc) Date: Wed, 28 Jul 2010 23:19:46 +0200 Message-ID: <501CC8FC-0348-4E6D-87D7-67AD82CD45B1@telia.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1280352012 28302 80.91.229.12 (28 Jul 2010 21:20:12 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 28 Jul 2010 21:20:12 +0000 (UTC) Cc: guile-user@gnu.org To: Mike Solomon Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Jul 28 23:20:11 2010 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OeE2s-0005ke-Fd for guile-user@m.gmane.org; Wed, 28 Jul 2010 23:20:10 +0200 Original-Received: from localhost ([127.0.0.1]:35037 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OeE2r-0001Dl-OV for guile-user@m.gmane.org; Wed, 28 Jul 2010 17:20:09 -0400 Original-Received: from [140.186.70.92] (port=49228 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OeE2Z-0001DH-T8 for guile-user@gnu.org; Wed, 28 Jul 2010 17:19:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OeE2Y-0002gL-R0 for guile-user@gnu.org; Wed, 28 Jul 2010 17:19:51 -0400 Original-Received: from smtp-out21.han.skanova.net ([195.67.226.208]:52397) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OeE2Y-0002g7-IN for guile-user@gnu.org; Wed, 28 Jul 2010 17:19:50 -0400 Original-Received: from h131n2-fre-d2.ias.bredband.telia.com (78.72.157.131) by smtp-out21.han.skanova.net (8.5.114) (authenticated as u26619196) id 4BC6D35002368045; Wed, 28 Jul 2010 23:19:48 +0200 In-Reply-To: X-Mailer: Apple Mail (2.936) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:8025 Archived-At: 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 bessel.cc because I'm using g+ > +), I > encountered the following error: > > bessel.cc: In function 'void init_bessel()': > bessel.cc:13: error: invalid conversion from 'scm_unused_struct* > (*)(scm_unused_struct*)' to 'scm_unused_struct* (*)(...)' > bessel.cc:13: 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) { init_guile(); 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" { #endif void init_bessel(); ... #ifdef __cplusplus } // extern "C" #endif #endif BESSEL_H The file bessel.c is compiled as C, but your C++ files include bessel.h. Hans