This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / The Mathematica Book / Principles of Mathematica / MathLink and External Program Communication  /

2.12.11 Special Topic: Running External Programs under a Debugger

MathLink allows you to run external programs under whatever debugger is provided in your software environment.
MathLink-compatible programs are typically set up to take arguments, usually on the command line, which specify what MathLink connections they should use.

Running an external program under a debugger.

Note that in order to get a version of an external program that can be run under a debugger, you may need to specify -g or other flags when you compile the program.


  • Set a breakpoint in the C function f.
  • (debug) break f
    Breakpoint set: f: line 1

  • Start the external program.
  • (debug) run -linkcreate

  • The program responds with what port it is listening on.
  • Link created on:

    Mathematica session

  • This connects to the program running under the debugger.
  • Out[1]= Install[LinkConnect[""]] LinkObject[, 1]

  • This calls a function which executes code in the external program.
  • In[2]:= f[16]


  • The external program stops at the breakpoint.
  • (debug) Breakpoint: f(16)

  • This tells the debugger to continue.
  • (debug) continue

    Mathematica session

  • Now f returns.
  • Out[2]= 561243