I am a .Net developer. I'm trying to build a Visual C++ application using C code generated from Mathematica (by another person). I don't have Mathematica installed on my machine. When I try to compile my code, I get this error:

"Error LNK2019: unresolved external symbol _WolframLibraryData_new referenced in function _wmain"

Can anyone help me with this? Do I need to have Mathematica installed on my machine in order to use C code compiled from Mathematica? Or are there some .h/.dll/.lib files that I should be including in my project? Any help would be appreciated.

This is a link to the Mathematica documentation which says this can be done:

Here is my code:

#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "WolframRTL.h"
#include "funct.h"

static WolframLibraryData libData=0;
int _tmain(int argc, _TCHAR* argv[])
    mint version=2;
    libData = WolframLibraryData_new(version); //error is at this line

    double A1[10][10]={{258.3379872132036,178.815628898537,274.5474024360497,674.9391898068819,223.178274172278,880.9581284722401,132.54033649875424,791.5414955768498,928.458244854092,853.042661440361},

    MTensor B1;
    mint type = MType_Real;
    mint dims[2];
    mint rank = 2;
    int err;
    dims[0] = 10;
    dims[1] = 10;
    err = libData->MTensor_new( type, rank, dims, &B1); 

    for(int i=0;i<10;i++)
        for(int j=0;j<10;j++)
            err = libData->MTensor_setReal(B1, dims, A1[i][j]);

    MTensor result;
    err = libData->MTensor_new(type, rank, dims, &result);  

    int A2=2;

    funct(libData, B1, A2, &result); //this is the function compiled from Mathematica

    double *res[10] ;

    for(int i=0;i<10;i++)
        res[i]= (*(libData->MTensor_getRealData))(&result[i]);
    return 0;
  • $\begingroup$ According to that page my answer was wrong, so I deleted it. Please include a link to that page in your question! $\endgroup$ – Szabolcs Apr 9 '14 at 3:10
  • $\begingroup$ I haven't attempted this, but I would imagine that at least you are going to need the mathematica libraries that implement the function calls you are trying to make. $\endgroup$ – image_doctor Apr 9 '14 at 10:14
  • $\begingroup$ I have tried adding all possible .lib, .dll and .h files as explained here: reference.wolfram.com/mathematica/CCodeGenerator/tutorial/…, but still getting the same error. Anyone have any suggestions? If you need any more info, please post a comment. $\endgroup$ – pag Apr 10 '14 at 0:00
  • 1
    $\begingroup$ You need to link the libWolframRTL during your compiling stage. I can create an executable from a slightly modified version of your source with this commandline. Remember that you don't need everything there, but you need to specify the position of the library and you need to tell -lWolframRTL. This can be different on Windows since I'm on Linux here! $\endgroup$ – halirutan Apr 10 '14 at 2:01
  • 1
    $\begingroup$ Tried it, but I'm getting the same error. $\endgroup$ – pag Apr 10 '14 at 3:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.