MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Setting up external functions to be called from Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82393] Re: Setting up external functions to be called from Mathematica
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Fri, 19 Oct 2007 04:58:37 -0400 (EDT)
  • References: <ff781v$nod$1@smc.vnet.net>

pinksheep415 wrote:
> Hi,
> 
> I'm trying to figure out how to call an external function from
> Mathematica.  Examples I've found so far doesn't give enough
> informations for a newbie like myself.
> 
> The following is content of an example MathLink template file, f.tm:
> 
> :Begin:
> :Function:      f
> :Pattern:       f[x_Integer, y_Integer]
> :Arguments:     {x, y}
> :ArgumentTypes: {Integer, Integer}
> :ReturnType:    Integer
> :End:
> 
> 1.  How do I create a MathLink template?  Can I just use text editor
> and save it with .tm extension?  Where should the file be saved?
> 
> Following is the content of an example c code, I named it f.c:
> #include "mathlink.h"
> 
> int main(int argc, char *argv[]) {
> return MLMain(argc, argv);
> }
> 
> int f(int x, int y) {
> return x+y;
> }
> 
> 2.  Although I copied "mathlink.h" file into INCLUDE folder for C
> compiler (I'm temporarily using Dev-C++), the compiler doesn't
> recognize MLMain(argc, argv);  Can anyone tell why?  Does this have to
> do w/ the kind of compiler I'm using?  Does this c file need to be in
> the same folder as the above .tm file?
> 
> 3.  After I get these files saved in the right folders, how do I use
> them?
> Any help would be greatly appreciated!!!
> 
> -selim50 at gmail.com
> 
> 
I am sure others will help you to link with C. I would just like to 
point out that if you can use Java instead, the whole process of linking 
to Mathematica is vastly easier because the interface (J/Link) is 
already built in.

Remember that Java implementations use Just In Time (JIT) technology, 
and thus execute at approximately the same speed as C. They also have a 
vast built-in library, and can themselves link to C/C++.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Ver 6.0 Subsets and Packed Array Question
  • Next by Date: Creating a popup menubox in a specified notebook
  • Previous by thread: Setting up external functions to be called from Mathematica
  • Next by thread: Re: Setting up external functions to be called from Mathematica