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: [mg16317] Re: Interfacing C++ code to Mathematica
  • From: Roopesh Mathur <mathurr at me.udel.edu>
  • Date: Sun, 7 Mar 1999 01:05:42 -0500
  • Organization: University of Delaware
  • References: <7bo0on$dpg@smc.vnet.net> <Pine.GSO.3.96rindlow.990305163901.8571A-100000@tintin.lysator.liu.se>
  • Sender: owner-wri-mathgroup at wolfram.com

> > 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. 
> 
> What you need to do is use "mprep" separately, that reads a MathLink
> template and produces C source. You can then use a standard C compiler to
> produce object code that can be linked together with your C++ code.
> Remember to use extern "C" { } when you include any C header file in your 
> C++ code.
> 


Hi!

Thank you for your suggestions! I will keep this in mind when writing my
Mathlink code.

An alternative method has been suggested by Kevin Leuthold of Wolfram
Research. FYI, I have included his method below. 

Sincerely,
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
---------------------------------------------------------------------------

 








  • Prev by Date: Re: Ploting 2 Lists
  • Next by Date: Re: Vector Field
  • Previous by thread: Re: Bug in Coefficient[ ]
  • Next by thread: Re: Interfacing C++ code to Mathematica