MathGroup Archive 1996

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

Search the Archive

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

  • To: mathgroup at
  • 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

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
:Function:      addtwo
:Pattern:       AddTwo[i_Integer, j_Integer]
:Arguments:     {i,j}
:ArgumentTypes: {Integer, Integer}
:ReturnType:    Integer

mathdir = /tools/math
mlincludes = $(mathdir)/Source/Includes
mllibrary = $(mathdir)/Bin/MathLink
libml= -lMLelf -lsocket -lnsl
        $(mathdir)/Bin/MathLink/mprep > $*.c
        cc -c $*.c -I$(mlincludes) -o $@

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

addtwo: addtwo.o
        cc addtwo.o -I$(mlincludes) -L$(mllibrary) $(libml) -lm -o $@
#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)

void bcopy(char* s,char* d,int 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>, penano at (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


  • 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++?)