Question: define_external custom wrapper

Hello,

 

I seem to be having trouble with the define_external command.

 

I want to call a C-library from maple, and I think I need to convert the maple data in C. So I need a custom wrapper.

 

But I can't get the simple example from here to work for me. Specifically, I tried this:

 

gcd3m.c:
===========================================
 /* Program to add two numbers from Maple */
#include
#include
#include

ALGEB gcd3( MKernelVector kv, ALGEB args )
{
    int a1, a2, r;

    if( MapleNumArgs(kv,args) != 2 )
        MapleRaiseError(kv,"Incorrect number of arguments");

    a1 = MapleToInteger32(kv,((ALGEB*)args)[1]);
    a2 = MapleToInteger32(kv,((ALGEB*)args)[2]);
    r = a1 + a2;

    return( ToMapleInteger(kv,(M_INT) r) );
}
===========================================

 

compile:

gcc -I/usr/maple/maple17/extern/include -fPIC -c gcd3m.c -o gcd3m.o
gcc -L/usr/maple/maple17/bin.X86_64_LINUX -fPIC gcd3m.o -shared -o gcd3.so -lmaple

 

Run in maple:

restart;
myAdd:=define_external('gcd3', 'MAPLE', 'LIB'="/home/mgibson/poly_c/gcd3.so");
myAdd(2,3);

Result:

myAdd := proc ()
    options call_external, define_external(gcd3, MAPLE, LIB = "/home/mgibson/poly_c/gcd3.so");
    call_external(0, 140052030785336, true, false, args)
end proc

 

"Kernel connection has been lost   You should save this worksheet..."

Please Wait...