Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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);

     MLActivate(link);

     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?

share|improve this question
2  
Get started here but this is the wrong venue to ask HOWTO questions. –  bobthechemist Jan 6 at 14:14
    
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. –  Szabolcs Jan 7 at 17:59
add comment

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.

share|improve this answer
    
This works, thanks a lot! –  arvindrajan92 Jan 8 at 11:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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