I am trying to create a GUI using Microsoft Visual Studio C++ 2010 by calling Mathematica in my codes.

I have done everything step by step as mentioned here

Then I wrote this code as mentioned in here

The code is as below

#include <mathlink.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
     MLENV env;
     MLINK link;
     int errno;

     env = MLInitialize(0);

     link = MLOpenArgcArgv(env, argc, argv, &errno);


     return 0;

The error I get is:

1>------ Build started: Project: mathematica_link_attempt1, Configuration: Debug Win32 ------
1>main.obj : error LNK2019: unresolved external symbol _MLOpenArgcArgv@16 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _MLActivate@4 referenced in function _main
1>C:\Users\arvindrajan\documents\visual studio 2013\Projects\mathematica_link_attempt1\Debug\mathematica_link_attempt1.exe : fatal error LNK1120: 2 unresolved externals

Any advice please?

  • 2
    $\begingroup$ Get started here but this is the wrong venue to ask HOWTO questions. $\endgroup$ Jan 6, 2014 at 14:14
  • $\begingroup$ I cannot help you with Visual Studio, as I do not use it myself (I only used the command line tools), but looking at the error messages it seems like you are not linking against the MathLink libraries. Instead of writing your own code, first try to compile some of the supplied examples and figure out how to link against the correct libraries in Visual Studio. Make sure you also translate the .tm file and compile the resulting C file. After you've managed to compile and run the examples, you can start writing your own code. $\endgroup$
    – Szabolcs
    Jan 7, 2014 at 17:59

1 Answer 1


As Szabolcs says, the problem is that you aren't linking with the MathLink libraries. The docs you cite give a method of doing this, but you might find it easiest (and it's easiest to explain) to simply add the ml32i4m.lib file to your Visual Studio project. (Use ml64i4m.lib, of course, if you are building a 64-bit program.) Right-click on your project in the Solution Explorer and select Add/Existing Item. In the dialog box that comes up, navigate to <mathematica dir>\SystemFiles\Links\MathLink\DeveloperKit\Windows\CompilerAdditions\mldev32\lib\ml32i4m.lib. The build should now work. For a 64-bit program, the correct path is <mathematica dir>\SystemFiles\Links\MathLink\DeveloperKit\Windows-x86-64\CompilerAdditions\mldev64\lib\ml64i4m.lib.

You won't be using a .tm file, as that feature is for calling from Mathematica into C, whereas you are doing the reverse.

  • $\begingroup$ This works, thanks a lot! $\endgroup$ Jan 8, 2014 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.