MathGroup Archive 1996

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

Search the Archive

Re: MathLink and C++ (can mathlink handle C++?)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3722] Re: MathLink and C++ (can mathlink handle C++?)
  • From: sherod at boussinesq.Colorado.EDU (Scott Herod)
  • Date: Wed, 10 Apr 1996 02:14:00 -0400
  • Organization: University of Colorado at Boulder
  • Sender: owner-wri-mathgroup at wolfram.com

I got this to work although admittedly on a simple example.  I'll include the
files here which hopefully will help.  (Note: cc is the C compliler and CC is
the C++ compiler.)

Scott Herod
===========================================================
addtwo.tm:
------------------------
:Begin:
:Function:      addtwo
:Pattern:       AddTwo[i_Integer, j_Integer]
:Arguments:     {i,j}
:ArgumentTypes: {Integer, Integer}
:ReturnType:    Integer
:End:
-------------------------

Makefile:
-------------------------
mathdir = /tools/math
mlincludes = $(mathdir)/Source/Includes
mllibrary = $(mathdir)/Bin/MathLink
libml= -lMLelf -lsocket -lnsl


addtwo.tm.o:
        $(mathdir)/Bin/MathLink/mprep addtwo.tm > $*.c
        cc -c $*.c -I$(mlincludes) -o $@

addtwo.o: addtwo.cc
        CC -c $*.cc -I$(mlincludes)  -o $@

addtwo: addtwo.o addtwo.tm.o
        cc addtwo.o addtwo.tm.o -I$(mlincludes) -L$(mllibrary) $(libml) -lm -o $@
-------------------------

addtwo.cc:
-------------------------
#include "mathlink.h"
#include <string.h>   // for memset and memcpy
extern "C" {

int addtwo(int i,int j)

{
    return i+j;
}

int main(int argc, char** argv)

{
    return MLMain(argc, argv);
}

void bzero(char* b, int n)
{
  memset(b,0,n);
}

void bcopy(char* s,char* d,int n)
{
  memcpy(d,s,n);
}

}
=================================================

Mathematica 2.2 for SPARC
Copyright 1988-94 Wolfram Research, Inc.
License valid through 31 Dec 1996.
 -- Open Look graphics initialized -- 

In[1]:= addlink = Install["addtwo"]

Out[1]= LinkObject[addtwo, 1, 1]

In[2]:= AddTwo[4,5]

Out[2]= 9
================================================

In article <4kd3eu$93v at dragonfly.wolfram.com>, penano at physics.ucla.edu (Penano Joe) writes:
|> Hi everyone,
|> 
|> Does anyone know if it's currently possible to intstall an
|> external C++ function through mathlink?  The function
|> I'm considering is very simple. It takes 3 doubles and returns 2
|> doubles. I've tried defining the function as an extern in C and 
|> passing the C program to mathlink but it can never find the C++
|> function.  Any help would be greatly appreciated.
|> 
|> Thanks,
|>  
|> -- 
|> Joe Penano
|> email: penano at physics.ucla.edu
|> 
|> 
|> 

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Method of images in MMA
  • Next by Date: Re: MathLink and C++ (can mathlink handle C++?)
  • Previous by thread: MathLink and C++ (can mathlink handle C++?)
  • Next by thread: Re: MathLink and C++ (can mathlink handle C++?)