# Items tagged with externalexternal Tagged Items Feed

### Use of imported DLL

January 05 2013 by Maple 15

Hi,

I'm trying to get a hold of using DLL with Maple at the moment.

Just to give you some background informations.

My Headerfile:

[code]

#include
using namespade std;

namespace WAVEFUNC
{
class
{
public:
...

### loading external swf files using xml...

November 21 2012 by Maple T.A. 8

0

1

I am experimenting with the new AS3 flash questions and everything works as expected except that I cannot load external swf files using a xml file. I have a parent swf file that behaves well, except that this parent swf cannot load the external swf files. It works flawlessly on my own website (which even does not have a cross-domain.xml file in the root directory).

Is there a restriction in Maple T.A. that prevents loading xml files by a swf (and/or loading external swf's in general)?

### External creation of a function

August 26 2012 by Maple

1

3

I would like to know if it is possible in an external program (C or Python) to create a Maple function ( Not a one liner, maybe a number of lines of Maple code ). Then call Maple to execute a separate Maple function and get the result back.

### External Library libgraphtheory.so could...

July 06 2012 by Maple 13

0

1

Hi!

I've got this annoying problem and it's quite simple reproducible.

> with(GraphTheory): G := Graph({{a, b}, {b, c}, {c, d}}); Edges(G);

Edges(G) returns me

Error, (in EdgesExt) external library libgraphtheory.so could not be found/used

It's the first time I encounter such a problem and have no idea on how to solve it, any advice?

I can see that libgraphtheory.so...

### Equation internal bisector and external...

January 24 2012 by Maple

Problem: Write the equation internal bisector and external bisector of a triangle ABC with A(1,2,-7), B(3,-1,-1), C(-5,14,-3). This is my code.

restart;> with(LinearAlgebra):> A:=: B:=: C:=: M:=:
>v:=1/Norm(A-B,2)*(A - B) + 1/Norm(A-C,2)*(A - C): M=A + v*t;
>u:= 1/Norm(A-B,2)*(A - B) - 1/Norm(A-C,2)*(A - C): M=A + u*t;
in the commands M = A + v*t and M = A + u*t, please comment for me. Thank you.

### RTable. Unduly garbaged?

November 10 2011 by

0

2

test.zip

1) Compile under vc express 2010 debug config. Don't forget point out your location of maplec.lib in configuration properties/Linker/General/Additional library directories. Assure that configuration is at least Debug or all.

2) Run sheet test_bombard.mw from Debug directory.

Have permanent crash on BombardByRandoms call. If i would transmit creating of rtable from 'InitInternal'...

### calling Pari from Maple

August 15 2011 by Maple

My Maple14 program occasionally needs to skip to Pari-GP to do some algebraic number theory calculations.

The code for WindowsXP is as follows (the code for Windows7 is a little different):

readstat("In a Pari window enter \\r p When done enter ; at the end of this line.");

Thus I need to put Pari in the foreground, and when done, bring my Maple program back to the

foreground. My program has already set p in the Pari directory to the appropriate Pari script.

### call python in maple

March 10 2011 by Maple

1

4

how can i call python code in maple like external call for C++/Java/C#...

i have a text parser written in python and want to use it

can someone help me?

### External Calling Setup

January 11 2011 by Maple

9

0

This post will explain how to configure the compiler and other tools that will be necessary for you to build the External Calling examples that will come in later posts.  This is an advanced topic and so this post is fairly complex.

First, I am going to be using the compilers via the command line, so you will need to familarize yourself with the terminal program on your particular OS.  You'll have to do this for yourself, but here are a few starting points:

Windows

Apple

I am going to assume that Linux and Solaris users are familar with using the terminal.

For Linux, Apple and Solaris, I am going to use gcc as the compiler.  For Linux you should use your distribution's package management system to get it, for Apple you need to install Xcode and for Solaris, well, gcc is probably already installed or you'll want to talk to you sys admin to have it installed (or if you are your own sys admin, you probably know how to install gcc for yourself).  For Windows, you need to install the Windows Software Development Kit.  If you already have a copy of Visual Studio C++ (Express or Professional) installed, then you already have these tools.

I am also going to use the "make" program to manage the building of the examples, thus you will need to install a version of make as well (you won't need to learn how make works unless you want to modify the examples).  I will be using gnu make, which should be easy to install on Linux and Solaris (similar to how you installed gcc) and it is included in Xcode for Apple.  For Windows, use this:

http://gnuwin32.sourceforge.net/packages/make.htm

Installing 32 bit make on 64 bit windows is fine.

Now you'll need to launch a terminal.  For Linux, Apple and Solaris this should be easy, on Windows go to the Windows SDK folder (or Windows Visual Studio folder) on the Start menu, there should be an icon for Windows SDK Command Prompt.  Click that to launch the terminal.  This version of the terminal has the environment configured to run the compiler.

On Windows you'll also have to add the location you installed make to your path, which can be done on 32 bit windows like this:

path=%PATH%;C:\Program Files\GnuWin32\bin

and on 64 bit Windows like this:

path=%PATH%;C:\Program Files (x86)\GnuWin32\bin

assuing you used the default install location for make.

You can test this by running "make" in the terminal.  If everything is set up correctly, make should run but not find a Makefile and it will raise an error.  If the path is not set properly, make won't be found you'll get a message saying that.

Path not set properly:

C:\Program Files\Microsoft SDKs\Windows\v7.1>make'make' is not recognized as an internal or external command,operable program or batch file.

Set the path:

C:\Program Files\Microsoft SDKs\Windows\v7.1>path=%PATH%;"C:\Program Files (x86)\GnuWin32\bin"

Make is now found, but there is no makefile in the current directory

C:\Program Files\Microsoft SDKs\Windows\v7.1>makemake: *** No targets specified and no makefile found.  Stop.

As a final test, I've attached a small example (test.zip) that contains a Makefile and a simple source file.  If you extract the files to a new directory, go to that new directoy in the terminal and run make (with make added to the path as described above) it should build an executable (test or test.exe).  You can run the executable by executing "test" on the command line.

By default the Makefile is configured for Windows, so Windows users won't need to change it, however other users will need to comment out the

WINDOWS=true

line in Makefile by changing it to

#WINDOWS=true

I know this is a little confusing, especially if you are not familar with the command line interface, therefore I encourage you post replies if you have problems.  Hopefully we will be able to answer your questions.  Once everyone has figured out how to get this simple example to compile and run on their system, the upcoming external calling examples will be (relatively) easy.

Good Luck!

Darin

### Introduction to External Calling

December 24 2010 by Maple

7

0

I've had a few request to provide some more information on External Calling, so I thought I would make a few posts about it. This first post will be a high level description of External Calling and how it works, with examples coming later. As External Calling is an advanced topic, I am going to assume you know how to compile a shared library and are generally familiar with the C language. Although this first post won't require any real programming knowledge.

What is External Calling?

External Calling is the name for Maple's ability to connect to and call functions from other programming languages. Maple uses this for various reasons. We have written our own libraries in C, C++ and Java to solve particular problems. We partner with various labs around the world who have developed code, often in languages like C or C++, so external calling is used to interface with their code. We also connect to high performance libraries like NAG and BLAS to provide those high performance routines in Maple. Of course, you can use External Calling to connect Maple to your code as well.

Although Maple can call various programming languages, the most common languages we connect to are C and C++, and those are the languages I am going to focus on.

How does it work?

In Maple, you call ?define_external or use the ?ExternalCalling package. Both these methods take a description of the function that you want to call and returns a Maple procedure. Normally you would assign the procedure to a name and then call the externally defined function just like any other Maple procedure.

There are a couple different ways to use define_external to connect to a shared library, the differences are mostly concerned with how the parameters given in Maple are converted to parameters used in the external function.

• Wrapperless external calling. With wrapperless external calling, Maple calls a function implemented in the shared library by automatically converting the values given in Maple into valid types for the external function.
• Generated wrappers: With generated wrappers, Maple automatically generates a small C library that handles conversions from Maple values to the values used in the external function. Using generated wrappers allows Maple to handle more data types, like call back procedures.
• Custom wrappers: A custom wrapper is a C function that you write yourself. This function accepts arguments as Maple data structures and returns a Maple data structure. You are responsible for converting the Maple data structures into whatever forms you need and converting your computed value back into a Maple data structure. Maple provides the External Calling API to assist in working with Maple from the externally defined function.

The first two forms of external calling are the easiest to do, however they are also the most limited. Internally we exclusively (I think) use the third, custom wrapper, form of external calling. That is the form I am going to talk about.

Custom Wrapper

The name "custom wrapper" is a bit of a misnomer. The function that you write does not need to "wrap" anything, it can implement anything you want. As long as you can convert the result into a Maple data structure, you can pass it back into Maple. In fact Maple also supports returning generic data, via the ?MaplePointer routines, but that is a more complex topic for a later blog post.

Your external function is simply a C function with the following calling convention:

ALGEB CustomWrapper( MKernelVector kv, ALGEB args )

ALGEB is the C data type that represents a Maple data structure. The MKernelVector is a data structure that acts as an intermediary between your external calling routines and the Maple engine. You will need to pass this structure back into the External Calling API functions. Both of these types, plus the External Calling API functions are defined in a header, maplec.h, that needs to be included in your code. I will provide more details when I provide examples.

The External Calling API

The External Calling API is a set of functions that we make available for working with the Maple Engine from external code. Maple also allows third party applications to load the Maple engine as a shared library, we call this ?OpenMaple. The External Calling functions are also available in OpenMaple, so you will often see OpenMaple used in the Maple help pages. Most functions can be used in both OpenMaple and External Calling, except for a few that are OpenMaple specific and involve starting and stopping the Maple Engine.

Maple's help system documents all the External Calling functions so you can see what is available. There is an overview of the external calling functions on this page, ?ExternalCalling,C,API. Briefly, however there are functions for converting Maple types to C and back, creating and interacting with Maple data structures (list, set, rtable, table, string, etc), creating and interacting with Maple language elements (names, procedures, etc), printing to the Maple interface, memory allocation, evaluating Maple statements and raising exceptions. There is even a C interface to the Task Programming Model.

Next Time...

In my next post I will provide some examples of using the External Calling API to actually do stuff in an externally defined procedure.  However, I am going to spend some time trying to figure out the easiest way for you to get the tools you'll need to be able to develop externally defined functions yourself, so my next post might take a bit of time.

Darin

### CDECL option in define_external

October 28 2010 by

External calling functions from Windows dlls in Maple uses __stdcall calling convention.

Most Windows dlls including <windows.h> are using that convention (called also WINAPI). However, C runtime dll (msvcrt.dll) and most mathematical dlls - such as gsl, PARI, etc. which would be very useful, are using __cdecl calling convention and functions from them can not be easily called from Maple. One has to create a wrapper dll with __stdcall calling convention for that. In particular, Axel Vogt did that for a part of PARI.

Would that be possible for Maplesoft developers to add option CDECL in define_external in Maple 15 allowing calling C library functions and functions from gsl, PARI, etc. directly from Maple, without a burden of writing __stdcall wrappers for them first?

### Fast writing to and reading from a disc

October 24 2010 by Maple

A couple of days ago I found out that gzread from the zlib library can be used for fast reading of binary files in Maple from the disk to memory - about 100 times faster than readbytes - something like in the following simplified example,

A:=Array(1..2^26,99,datatype=integer[1]):

time(writebytes("A",A));close("A");

9.360

B:=Array(1..2^26,1,datatype=integer[1]):
time(readbytes("A",B));close("A");

8.065
B[1],B[-1];

99, 99

myreadbytes:=proc(f)
local gzopen, gzread, gzclose, n, p, A;
gzopen:=define_external('gzopen',
'path'::string,
'mode'::string,
'RETURN'::integer[4],
'LIB'="zlibwapi.dll");
gzread:=define_external('gzread',
'file'::integer[4],
'buf'::REF(ARRAY(datatype=integer[1])),
'len'::integer[4],
'RETURN'::integer[4],
'LIB'="zlibwapi.dll");
gzclose:=define_external('gzclose',
'file'::integer[4],
'RETURN'::integer[4],
'LIB'="zlibwapi.dll");
n:=FileTools:-Size(f);
A:=Array(1..n,datatype=integer[1]);
try p:=gzopen(f,"rb");
if gzread(p,A,n)=n
then return A end if
finally gzclose(p)
end try
end proc:
time(assign(C=myreadbytes("A")));

0.062

C[1],C[-1];

99, 99

'time(myreadbytes("A"))'\$5;

0.078, 0.062, 0.046, 0.046, 0.046

E:=Array(1..2^26,2,datatype=integer[1]):
time(ArrayTools:-Copy(A,E));

0.093

That needs some tweaking, because that works only on uncompressed files. If a file ("A" in this example) was gzipped, then the gzread would ungzip n (uncompressed) bytes in it in this example, instead of copying it into the memory - but it is not a big deal, in general.

Does anybody know about a similar replacement for writebytes? gzwrite doesn't work for copying (it compresses the array.)

I used the zlibwapi.dll library from http://www.winimage.com/zLibDll/index.html, it is a version of zlib 1.2.5 (written by Jean-Loup Gailly and Mark Adler) built by Gilles Vollant. The code is for a 32-bit system (Windows). That should work in 32-bit Linux after replacing that dll with standard libz.so.1, as well as on 64-bit systems after replacing integer[4] with integer[8] in most places.

### Error, external linking: error loading...

August 27 2010 by Maple

2

7

Hi,

I'm trying to use a simple DLL in maple, which I create based on Maple external linking examples..

int __stdcall mult( int a, int b )
{
return a * b;
}

and I compiled it with Visual Studio 2010 compiler, but when I use it in Maple I recieve the error

"Error, external linking: error loading external library"

thanks

### Using 3rd party external functions in...

July 27 2010 by Maple

5

3

There are two pieces of extended functionality that I quite often want from the Maple Compiler. The first (task A) is to be able to link in and use an arbitrary function from some other external ("3rd party") shared library, within my Compile'd Maple procedure. The second (task B) is to directly call the compiled Maple procedure from within some computational routine in a 3rd party shared library (which I would then access using define_external). This post is about the first of those, task A.

### Interrupting External Code in Maple

May 30 2008 by Maple

1

7

If you're writing an external library to be called from Maple, then you have the following problem. The user wants to interrupt your code. They are valiantly pressing control-C or the stop button in the Maple GUI, as your code grinds their machine to a halt. What do you do ?

 Page 1 of 1