MathGroup Archive 2001

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

Search the Archive

Re: Mathlink problem

  • To: mathgroup at
  • Subject: [mg28179] Re: [mg28144] Mathlink problem
  • From: "P.J. Hinton" <paulh at>
  • Date: Tue, 3 Apr 2001 02:37:57 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

On Sun, 1 Apr 2001, Larry Gorski wrote:

> Hello.  I'm trying to link a C language program to a Mathematica
> notebook.

Actually, the front end does not interact directly with the program you
are trying to build.  As long as the executable you build runs on the same
machine as the Mathematica kernel used by the front end, the executable is
launched and manipulated by the kernel.

> I'm using Mathematica 4.1 and Microsoft Visual C++ V 6.0. I'm
> practicing with the "ADDTWO" example from Mathematica/Mathlnk. First,
> I had a problem prepoecessing the .tm file.  Visuall C++ couldn't seem
> to find the file.  I finally just ran "mprep -o addtwotm.c"
> and copied the output file "addtwotm.c" to the correct subdirectory
> (workspace in Visuall C++).

It is not clear from this description what steps you took to set up your
project, but you probably should have added the .tm file to the project
and then set up a custom compilation step for the file that invokes mprep.
This is discussed in the system-specific notes for the Windows MathLink
Developer's Kit.  Paste this expression in a notebook and evaluate it to
view this documentation in the Help Browser window.

    "AddOns", {"Building", "Microsoft"}

Refer to the subsection titled "Using the integrated development
environment, V6.0"

> I went back to Visual C++ and openen the correct workspace.
> Addtwotm.c was identified as a source file along with addtwo.c.  So I
> tried to build "addtwo.exe"  It seemed to work i.e. 0 Errors, 0
> Warnings.  I went backed to Matematica and tried to install
> "addtwo.exe".  First, it couldn't find the file.

The Mathematica kernel does not search everywhere on your local filesystem
for files when you invoke the Install[] command.  You will most likely
want to do one of the following:

1) Temporarily set the kernel's working directory to the location of the
executable file you want to launch using the built-in function

2) Add the directory wher the executable resides to the kernel's $Path
session variable.

> The file was created by Visual C++ but it was in the .\addtwo\debug
> subdirectory.  That made me a bit nervous.  In any event, after
> providing the path to \addtwo.exe, the expected function calls did not
> work.  Mathematica seemed to act as if addtwo was not a function
> recognizable to it.

The Install[] function should have returned a LinkObject[] as the result
of an evaluation.  You can check to see what function definitions were
added by evaluating LinkPatterns[].  Here is an example:

lnk = Install["addtwo.exe"];


You should get something like this for the output:

{AddTwo[i_Integer, j_Integer]}

If you get something else, please repost to this forum with your result.
That might give us a better idea as to what is going on.

> I very inexperienced in these things.  If you can help me understand
> where I went wrong and how to correct my problems, I would appreciate it
> but please keep the explanations simple.

You may also want to invest some time becoming familiar with your
development tools.  Specifically, the following topics would be relevant
to your work.  From the Visual C++ Online Documentation, click open the
following help categories:

Visual C++ Documentation
  Visual C++ User's Guide
    Working With Projects
      How Do I... Topics: Working With Projects
        Adding and Removing Files from Projects

Visual C++ Documentation
  Visual C++ User's Guide
    Working With Projects
      Adjusting the Build Setings
         Specifying Custom Build Rules

This will help you set up the mprep step within your project.

P.J. Hinton
User Interface Programmer                         paulh at
Wolfram Research, Inc.
Disclaimer: Opinions expressed herein are those of the author alone.

  • Prev by Date: Re: C, MathLink or Java, J/Link
  • Next by Date: Polar Grids in Mathematica
  • Previous by thread: Re: Mathlink problem
  • Next by thread: Re: Novice question regarding variable naming and subscripts