call C routine on a Linux computer [message #18841] |
Tue, 08 February 2000 00:00  |
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  |
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.
|
|
|