* Guile, C++, and Mac OS X 10.4 (powerpc)
@ 2010-07-28 19:49 Mike Solomon
2010-07-28 21:19 ` Hans Aberg
0 siblings, 1 reply; 6+ messages in thread
From: Mike Solomon @ 2010-07-28 19:49 UTC (permalink / raw)
To: guile-user
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* (*)(...))'
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)
I know that Lilypond uses a workaround where it defines something called
GUILE_ELLIPSIS, but I am not sure how this logic can be integrated into a
small snippet of code.
Anyway, if any of you know how I can make the bessel example compile on OS X
10.4 PPC using g++ 4.0.1, I'd much appreciate it!
Cheers,
Mike
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Guile, C++, and Mac OS X 10.4 (powerpc)
2010-07-28 19:49 Guile, C++, and Mac OS X 10.4 (powerpc) Mike Solomon
@ 2010-07-28 21:19 ` Hans Aberg
2010-07-29 8:04 ` Mike Solomon
2010-08-18 13:49 ` Ludovic Courtès
0 siblings, 2 replies; 6+ messages in thread
From: Hans Aberg @ 2010-07-28 21:19 UTC (permalink / raw)
To: Mike Solomon; +Cc: guile-user
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 <http://www.gnu.org/licenses/
>
*/
#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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Guile, C++, and Mac OS X 10.4 (powerpc)
2010-07-28 21:19 ` Hans Aberg
@ 2010-07-29 8:04 ` Mike Solomon
2010-07-29 12:43 ` Linas Vepstas
2010-08-18 13:49 ` Ludovic Courtès
1 sibling, 1 reply; 6+ messages in thread
From: Mike Solomon @ 2010-07-29 8:04 UTC (permalink / raw)
To: Hans Aberg; +Cc: guile-user
Dear Hans,
Thank you very much for your response. I'm including here some stuff I
did (a sort of c++ to c and back again) in hopes that it may be useful to
others trying to do the same thing. Asterisk delimiters mean a new file,
whose name is in the first comment.
***
//bessel-extension.h
#ifndef BESSEL_EXTENSION_H
#define BESSEL_EXTENSION_H
#ifdef __cplusplus
extern "C" {
#endif
int silly (int x);
#ifdef __cplusplus
} // extern "C"
#endif
#endif BESSEL_EXTENSION_H
***
//bessel-extension.cc
#include "bessel-extension.h"
#include "vector"
int
silly (int x)
{
// include random c++ functionality
std::vector<int> *foo = new std::vector<int>;
foo->push_back (1);
foo->push_back (2);
int rv = foo->at (0) +foo->at (1)+x;
delete foo;
return rv;
}
***
// bessel.h
#ifndef BESSEL_H
#define BESSEL_H
#ifdef __cplusplus
extern "C" {
#endif
void init_bessel();
#ifdef __cplusplus
} // extern "C"
#endif
#endif BESSEL_H
***
// bessel.c
#include <math.h>
#include <libguile.h>
#include <bessel.h>
#include <bessel-extension.h>
SCM
j0_wrapper(SCM x)
{
return scm_make_real(j0 (scm_num2dbl(x,"j0")));
}
SCM
silly_wrapper(SCM x)
{
return scm_from_int(silly (scm_to_int (x)));
}
void
init_bessel()
{
scm_c_define_gsubr("j0",1,0,0,j0_wrapper);
scm_c_define_gsubr("silly",1,0,0,silly_wrapper);
}
***
// bessel.cc
#include "bessel-extension.h"
#include "bessel.h"
***
Then, compile:
g++ -c bessel-extension.cc
gcc -c -I. -fPIC bessel.c
g++ -bundle bessel-extension.o bessel.o -o libguile-bessel.so -lguile
bessel.cc
(this last line will change based on your platform...ie bundle becomes
shared for linux...use libtool if you're really serious about making
something durable!)
Then:
guile> (load-extension "./libguile-bessel" "init_bessel")
guile> (j0 2)
0.223890779141236
guile> (silly 6)
9
Hope this helps the fledgling C++ programmer using guile!
~Mike
On 7/28/10 11:19 PM, "Hans Aberg" <haberg-1@telia.com> wrote:
> 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
> <http://www.gnu.org/licenses/
>>
> */
>
> #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
>
>
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Guile, C++, and Mac OS X 10.4 (powerpc)
2010-07-29 8:04 ` Mike Solomon
@ 2010-07-29 12:43 ` Linas Vepstas
0 siblings, 0 replies; 6+ messages in thread
From: Linas Vepstas @ 2010-07-29 12:43 UTC (permalink / raw)
To: Mike Solomon; +Cc: guile-user
On 29 July 2010 03:04, Mike Solomon <mikesol@ufl.edu> wrote:
>
> Hope this helps the fledgling C++ programmer using guile!
If anyone is interested, I have a C++ template class that is analogous to
scm_c_define_gsubr for object methods (and calls scm_c_define_gsubr
under the covers) One just says:
MyTestClass *mtc = new MyTestClass(42);
define_scheme_primitive("bingo", &MyTestClass::my_func, mtc);
and a corresponding scheme function, with appropriate signature
and argument conversion, gets created.
--linas
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Guile, C++, and Mac OS X 10.4 (powerpc)
2010-07-28 21:19 ` Hans Aberg
2010-07-29 8:04 ` Mike Solomon
@ 2010-08-18 13:49 ` Ludovic Courtès
2010-08-18 14:16 ` Hans Aberg
1 sibling, 1 reply; 6+ messages in thread
From: Ludovic Courtès @ 2010-08-18 13:49 UTC (permalink / raw)
To: guile-user
Hi,
Hans Aberg <haberg-1@telia.com> writes:
> 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.
I don’t think that this is the cause of the problem.
The problem instead stems from use of function declarators with empty
parenthesis, which is also an obsolescent C feature, as discussed here:
http://savannah.gnu.org/bugs/?23681
I fixed a few of these in Guile 1.9, but not all of them, and not
‘scm_c_define_gsubr’ in particular.
I would appreciate patches in this area. :-)
Thanks,
Ludo’.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Guile, C++, and Mac OS X 10.4 (powerpc)
2010-08-18 13:49 ` Ludovic Courtès
@ 2010-08-18 14:16 ` Hans Aberg
0 siblings, 0 replies; 6+ messages in thread
From: Hans Aberg @ 2010-08-18 14:16 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-user
On 18 Aug 2010, at 15:49, Ludovic Courtès 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.
>
> I don’t think that this is the cause of the problem.
>
> The problem instead stems from use of function declarators with empty
> parenthesis, which is also an obsolescent C feature, as discussed
> here:
>
> http://savannah.gnu.org/bugs/?23681
>
> I fixed a few of these in Guile 1.9, but not all of them, and not
> ‘scm_c_define_gsubr’ in particular.
>
> I would appreciate patches in this area. :-)
I got those when doing a templates in a C++ wrap, and just assumed it
had something to do with that SCM was a pointer.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-08-18 14:16 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-28 19:49 Guile, C++, and Mac OS X 10.4 (powerpc) Mike Solomon
2010-07-28 21:19 ` Hans Aberg
2010-07-29 8:04 ` Mike Solomon
2010-07-29 12:43 ` Linas Vepstas
2010-08-18 13:49 ` Ludovic Courtès
2010-08-18 14:16 ` Hans Aberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).