StartMaple - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


start an OpenMaple session


Calling Sequence




Calling Sequence

StartMaple(argc, argv, cb, user_data, info, err)




number of startup command-line arguments (int)



startup command-line arguments (char**)



callback Vector (MCallBackVector)



data passed during invocation of callbacks (void*)



reserved for internal use (void*)



string buffer (char*)



This function can be used in external code with OpenMaple. It does not work as part of define_external.


StartMaple initializes an OpenMaple session.  When successful, an MKernelVector handle is returned.  This handle is needed as an argument to all OpenMaple API functions. An MKernelVector handle can also be obtained as the first argument sent to an external function defined by define_external.


Startup options described in ?maple can be used for starting OpenMaple by specifying them in argv.  For example, to load the initialization file, /home/myinit, at startup, set argv[1] = "-i", and argv[2] = "/home/myinit".  If these are the only arguments, set argc = 3 (the number of arguments including the implicitly defined argv[0] string which must be set to "maple").


If initialization fails, StartMaple returns NULL and fills in the string provided in the err parameter.  This string, if non-NULL must be preallocated to fit at least 2048 characters (including the NULL terminator). Maple does not generate error messages longer than this.


An initialization failure stating that the license.dat file does not exist, usually indicates that OpenMaple cannot find the path to the Maple installation.  In Windows, it can find this in the registry, but in UNIX and on the Macintosh, the environment variable $MAPLE must be set to the root directory of the Maple installation, for example, /usr/local/maple.  In addition, to the $MAPLE environment variable, the $PATH, or $LD_LIBRARY_PATH may also need to be set.


The info parameter is reserved for internal use and must always be set to NULL.


The user_data parameter is an arbitrary user-supplied value. It is the first argument passed to the callback functions.


The cb parameter specifies a collection of functions that Maple uses to return results to your application.  The MCallBackVector structure is defined as follows.

  typedef struct {

      void (M_DECL *textCallBack)( void *data, int tag, char *output );

      void (M_DECL *errorCallBack)( void *data, M_INT offset,

                    char *msg );

      void (M_DECL *statusCallBack)( void *data, long kilobytesUsed,

                     long kilobytesAlloc, double cpuTime );

      char * (M_DECL *readLineCallBack)( void *data, M_BOOL debug );

      M_BOOL (M_DECL *redirectCallBack)( void *data, char *name,

                     char *mode );

      char * (M_DECL *streamCallBack)( void *data, char *name,

                       M_INT nargs, char **args );

      M_BOOL (M_DECL *queryInterrupt)( void *data );

      char * (M_DECL *callBackCallBack)( void *data, char *output );

  } MCallBackVector, *MCallBack;


All callback functions have defaults that direct output to another callback, or to stdout.  To use the default, set the function pointer to NULL.  It is recommended that you always define a textCallBack function.


Each function takes one or more parameters. All take a generic data parameter. The data parameter is passed the value of the user_data parameter given to StartMaple.


If a callback function needs the MKernelVector of the kernel from which it was called, your application can use the user_data parameter to pass this information. For example, the data parameter can pass a pointer to an object or structure containing the MKernelVector.


All the API functions, including the callback functions, are declared with the M_DECL modifier. The functions assigned to the callback vector must also be declared with the M_DECL modifier.


For more information on the callback functions, see ?textCallBack, ?errorCallBack, ?statusCallBack, ?readLineCallBack, ?redirectCallBack, ?streamCallBack, ?queryInterrupt, and ?callBackCallBack.


    #include <stdio.h>

    #include <stdlib.h>

    #include "maplec.h"

    static void M_DECL textCallBack( void *data, int tag, char *output )




    int main( int argc, char *argv[] )


    char err[2048];

    MKernelVector kv;

    MCallBackVectorDesc cb = {  textCallBack,









    ALGEB r, l;

    if( (kv=StartMaple(argc,argv,&cb,NULL,NULL,err)) == NULL ) {

        printf("Fatal error, %sn",err);

        return( 1 );


    r = MapleKernelOptions(kv,"mapledir",NULL);

    if( IsMapleString(kv,r) )

        printf("Maple directory = \%s\nn",MapleToString(kv,r));

    printf("Evaluate an integral: nt");

    r = EvalMapleStatement(kv,"int(1/(x^4+1),x);");




    r = MapleEval(kv,r);

    MapleALGEB_Printf(kv,"nEvaluated at x=0, the integral is: %an",r);

    l = MapleListAlloc(kv,3);




    MapleALGEB_Printf(kv,"nHere is the list: %an",l);

    return( 0 );


See Also