comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: g++ with IDL call_external
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: g++ with IDL call_external [message #45838] Tue, 11 October 2005 19:05
tdaitx is currently offline  tdaitx
Messages: 5
Registered: July 2005
Junior Member
As Nigel said, C++ compilers mangle functions name differently than C
compilers, since they have to support function overloading. You should
use

#ifdef __cplusplus
extern "C" {
#endif
<all your C prototype code goes here>
#ifdef __cplusplus
}
#endif

and you'll be able to compile it with both gcc and g++.

You should really take a look at
http://developers.sun.com/prodtech/cc/articles/mixing.html and
http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html, both an
excellent source on how to mix C and C++ code.

Regards,
Tiago S Daitx
Re: g++ with IDL call_external [message #45844 is a reply to message #45838] Tue, 11 October 2005 12:22 Go to previous message
Denis Barkats is currently offline  Denis Barkats
Messages: 4
Registered: October 2005
Junior Member
Thanks Nigel,

that is exactly it
if I nm the simple.o I see there is a function called _Z6simplev and
I can call that one.

Thanks
Re: g++ with IDL call_external [message #45851 is a reply to message #45844] Tue, 11 October 2005 05:07 Go to previous message
Nigel Wade is currently offline  Nigel Wade
Messages: 286
Registered: March 1998
Senior Member
Denis Barkats wrote:

> Hi, I've been trying to use call_external from within IDL to call a
> piece of code that I compiled with g++ instead of gcc. Here is the
> exemple.
>
> i have a file simple.c:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int Simple() {
> return 13;
> }
>
> Using gcc I do
> -gcc -c simple.c
> -gcc -bundle -flat_namespace -o simple.so simple.o
> which creates the sharable librairie simple.so which I can call from
> IDL as
> -print,call_external('/Users/denis/idl/bicep/simple.so','Sim ple',
> /unload)
> 13
>
> So everything is fine.
> However, now if I use g++
>
> g++ -c simple.c
> g++ -bundle -flat_namespace -o simple.so simple.o
> print,call_external('/Users/denis/idl/bicep/simple.so','Simp le',
> /unload)
> % CALL_EXTERNAL: Error loading sharable executable.
> Symbol: Simple, File =
> /Users/denis/idl/bicep/simple.so
> symbol not found
> it does not seem to work.
>
> DO any of you g++ users have any idea ?
> Thanks


My guess would be that you need to disable the g++ name-mangling. If you
look at the names produced in simple.o by g++ you will see that Simple
has been mangled into something strange like _X6Simplev (the mangled
name includes a signature, to allow overloading). You need to declare
Simple in an extern 'C', to tell g++ that it's a C function, not a C++
one, so overloading and mangling can be disabled.

I'll leave it as an exercise for the OP to determine how to do this
(principally because I can't remember the exact semantics).


--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
Re: g++ with IDL call_external [message #45865 is a reply to message #45851] Mon, 10 October 2005 13:25 Go to previous message
wem is currently offline  wem
Messages: 6
Registered: October 2005
Junior Member
g++ is the traditional nickname of GNU C++, a freely redistributable C++ compiler. It is part of gcc, the GNU compiler suite, and is currently part of that distribution.
( http://directory.fsf.org/GNU/gpp.html )

thought g++ calls gcc or vice versa, but that they should have the same output ...



Denis Barkats wrote:
> Hi, I've been trying to use call_external from within IDL to call a
> piece of code that I compiled with g++ instead of gcc. Here is the
> exemple.
>
> i have a file simple.c:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int Simple() {
> return 13;
> }
>
> Using gcc I do
> -gcc -c simple.c
> -gcc -bundle -flat_namespace -o simple.so simple.o
> which creates the sharable librairie simple.so which I can call from
> IDL as
> -print,call_external('/Users/denis/idl/bicep/simple.so','Sim ple',
> /unload)
> 13
>
> So everything is fine.
> However, now if I use g++
>
> g++ -c simple.c
> g++ -bundle -flat_namespace -o simple.so simple.o
> print,call_external('/Users/denis/idl/bicep/simple.so','Simp le',
> /unload)
> % CALL_EXTERNAL: Error loading sharable executable.
> Symbol: Simple, File =
> /Users/denis/idl/bicep/simple.so
> symbol not found
> it does not seem to work.
>
> DO any of you g++ users have any idea ?
> Thanks
>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: group leader for iTools
Next Topic: Re: measuring lines

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:55:56 PDT 2025

Total time taken to generate the page: 0.00659 seconds