Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
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.
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.