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

Home » Public Forums » archive » call C routine on a Linux computer
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
call C routine on a Linux computer [message #18841] Tue, 08 February 2000 00:00 Go to next message
Shunrong Zhang is currently offline  Shunrong Zhang
Messages: 1
Registered: February 2000
Junior Member
Hi,

I was trying to call a simple C routine using call_external, but failed.

The C code file is sample.c (IDL 5.1 External Development Guide, p 108)


#include <stdio.h>
float sum_array(argc, argv)
int argc;
void *argv[];
{
float *fp, s = 0.0; int n;
for(n = *(int *) argv[1], fp = (float *) argv[0]; n--; )
s += *fp++;
return(s);}

I worked with a Linux computer, and the C compiler is gcc (v2.7). So I
compiled and linked in the following way,

cc -fPIC -c sample.c
ld -shared -o sample.so sample.o

Then from IDL,

X = FINDGEN(10)
S = CALL_EXTERNAL('sample.so', '_sum_array' X, N_ELEMENTS(X),
/F_VALUE)

There came out a message of syntax error.
I changed the entry point name from '_sum_array' to 'sum_array', the
same error message came out.

What was my entry point name ? Anything wrong in my above procedure ?

Thank you in advance !

S.-R.
Re: call C routine on a Linux computer [message #18922 is a reply to message #18841] Wed, 09 February 2000 00:00 Go to previous message
Steve[2] is currently offline  Steve[2]
Messages: 7
Registered: January 1999
Junior Member
Shunrong Zhang wrote:

> Hi,
>
> I was trying to call a simple C routine using call_external, but failed.
>
> The C code file is sample.c (IDL 5.1 External Development Guide, p 108)
>
> #include <stdio.h>
> float sum_array(argc, argv)
> int argc;
> void *argv[];
> {
> float *fp, s = 0.0; int n;
> for(n = *(int *) argv[1], fp = (float *) argv[0]; n--; )
> s += *fp++;
> return(s);}
>
> I worked with a Linux computer, and the C compiler is gcc (v2.7). So I
> compiled and linked in the following way,
>
> cc -fPIC -c sample.c
> ld -shared -o sample.so sample.o
>

It looks like the problem is in your C compilation: when you use cc,
use: cc -fPIC sample.c -o sample.o . gcc will output executable as 'a.out'
unless you use the -o option. Is your compilation giving you a sample.o
file?



>
> Then from IDL,
>
> X = FINDGEN(10)
> S = CALL_EXTERNAL('sample.so', '_sum_array' X, N_ELEMENTS(X),
> /F_VALUE)
>
> There came out a message of syntax error.
> I changed the entry point name from '_sum_array' to 'sum_array', the
> same error message came out.
>
> What was my entry point name ? Anything wrong in my above procedure ?
>
> Thank you in advance !
>
> S.-R.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Passing optional parameters through a wrapper routine
Next Topic: Object recognition

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

Current Time: Wed Oct 08 17:38:38 PDT 2025

Total time taken to generate the page: 0.00470 seconds