MathGroup Archive 1999

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

Search the Archive

Re: Interfacing C++ code to Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16298] Re: Interfacing C++ code to Mathematica
  • From: kevinl (Kevin Leuthold)
  • Date: Sun, 7 Mar 1999 01:05:33 -0500
  • Organization: Wolfram Research, Inc.
  • References: <7bo0on$dpg@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Roopesh,

You should be able to compile MathLink programs using C++ pretty much the
same way you would with C.  If you like using mcc, you can force it to use
whatever compiler you want, even a C++ compiler, by setting your CC environment
variable:

setenv CC g++

Also, you don't need to use mcc - compiling a MathLink program is a matter of
including mathlink.h in the appropriate files, then linking against libML.a.
There is a sample makefile in the folder 
AddOns/MathLink/DevelopersKits/<System>/MathLinkExamples.

However, there is a bug in mathlink.h that may prevent you from compiling your
program using a C++ compiler.  The bug is that certain function prototypes are not
wrapped in extern "C" {}.  You can download an updated mathlink.h that fixes this
problem at http://www.wolfram.com/support/MathLink/Updates/mathlink.h.html.

Kevin Leuthold
MathLink Group
Wolfram Research

Roopesh Mathur <mathurr at me.udel.edu> writes:


>I have a question on interfacing C++ code to Mathematica. Hope you or
>other members of the Mathematica User Group can answer it. A short
>description :

>I have an analytical model for a manufacturing process, written as a
>notebook in Mathematica 3.0, which I would like to use to optimize the
>process. For this,the optimization algorithm, which is written in C++,
>needs to call the model repetitively, in an optimization loop. I have come
>up with the following idea to do this:

>1. Convert the hitherto open-ended model into a function which returns the
>relevant data after computation. 

>2. Use Mathlink to connect to the Mathematica kernel and call this
>function from the optimization code.

>The problem is that Mathlink code embedded in my C++ program, needs to be
>compiled, while the book recommends 'mcc', which can handle only C code. I
>would like to solve this problem without changing the C++ code to C, since
>I am using the object oriented capabilities of C++ significantly. 

>I tend to believe that with the number of people using C++, someone must
>have encountered this problem before.

>Any suggestions and experience would be welcome! Please reply to my e-mail
>address : mathurr at me.udel.edu also.

>Sincerely,
>Roopesh







  • Prev by Date: Re: Using Utilities`Notation` in a package
  • Next by Date: Re: "ExtendGraphics`Contour`"
  • Previous by thread: Re: Interfacing C++ code to Mathematica
  • Next by thread: Re: Interfacing C++ code to Mathematica