I’ve been trying to call C/Fortran routines from within Maple 7 on Mac OS9 using it’s define_external function but to no avail.
What I did was to compile the sample mat_mult c function from the define_external help page in to a Unix library as follows:
gcc -c mat_mult.c ar r libstuff.a mat_mult.c ranlib libstuff.a
(I should perhaps make it into a Mac library file instead but I’m not quite sure how..)
and then...
> mat_mult := > define_external('mat_mult', > a::ARRAY(1..i,1..j,float[8]), > b::ARRAY(1..j,1..k,float[8]), > c::ARRAY(1..j,1..k,float[8]), > i::integer[4], > j::integer[4], > k::integer[4], > LIB="mat_mult.a"):
as suggested.
Upon excecution of the above, Maple returns
on Mac OS9. I’ve also tried running it in Windows with the same library file as well but it doesn’t work either (although I get a different error message).
I have experimented a bit with external c-code under LINUX, the following commands produce working code which I could execute from MAMPLE along the guidelines given in the online help-page.
[Note that some switches are needed which you have not choosen, you have to look up elsewhere, what options are needed on a MAC to compile code for shared libaries (the code has to be free of relocation stuff)
%> gcc -fPIC -g -c -Wall mylib.c /* compile the c-source */ %> gcc -shared -Wl,-soname,libstuff.so.1 -o libstuff.so.1.0.1 mylib.o -lc /* create a shared libary where the code is lined again the standart c-libary of linux */ /sbin/ldconfig -n ./ /* anounce the new libary to the system (your ar command ?)*/ cp libstuff.so.1.0.1 /opt/maple/MapleVII/bin.IBM_INTEL_LINUX/libstuff.so /* copy the libary to a location where MAPLE can find it, here simply in the bin.xxxxx directory (dangerous) */
Then take the example worksheet from the online help-page and test the code.
Beside the fact, that I had to use FORTRAN ORDER to get the correct result in my c-program, everything worked out as explained in the help page.
[evalm( A &* B) = C, while the external called function comes up with C^T if not
FORTRAN ORDER was choosen] I was on the way to write some fast code for a large
package to speed up computations.
However, if external routines are short, no gain in speed is accomplished, since the wrapper takes very much time.
I found it quite not easy to get directly data, i.e. algebraic expressions not numerics, from MAPLE and stoped for now with the project and stayed with generic MAPLE code.
Well, you will find my _two_ postings on this subject in the archives of this mailing list at
http://www.scg.uwaterloo.ca/~maple_gr/Digests/
Just download the file ’Digest01.07’ and search for "External calling on Windows platforms".