16
$\begingroup$

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
    Initialize_funct(libData);

    double A1[10][10]={{258.3379872132036,178.815628898537,274.5474024360497,674.9391898068819,223.178274172278,880.9581284722401,132.54033649875424,791.5414955768498,928.458244854092,853.042661440361},
    {326.39463864136036,65.54849946988038,7.013535695540694,760.8886179075255,892.4870852590801,154.85960584875158,993.9999549781506,376.1879698639858,852.6107989941474,643.4517088040595},
    {182.6857552274334,183.10740080449298,115.54339508284843,739.9140368208969,924.3477680142298,4.291771905955958,840.9959926467988,64.97484701401486,701.1694938419519,123.33364343371585},
    {708.4556561480445,273.433351437165,772.7112489878598,270.29098199335476,382.06101750668415,207.88485196728465,765.6977132923191,509.4023640858293,489.57393224760403,53.02524611853305},
    {771.6977583141684,133.21439422184343,636.9631332534566,409.5735373144735,589.012003086735,950.1069934173505,521.4197381706082,669.6595004935767,664.6642350725052,945.8152215113945},
    {680.4237455238093,604.6846534795618,963.4947412305534,822.4815780776786,971.9680893757649,331.25130204239684,190.78349224269357,552.1905960843238,589.9070718690806,123.36645007511217},
    {425.08577895037445,42.78823199849459,100.33313962147668,70.34120395657912,653.3880206362061,909.5738377766511,463.37000636802014,660.7676666421056,64.37601754947093,959.4668443593006},
    {941.9502681974119,991.1081661485289,399.7117824769657,13.651622847906154,261.5265226736025,386.4235126689671,436.2170412464123,191.17004477022746,289.5584332978377,55.17221062657027},
    {245.43354900371878,638.9794486859037,699.651361428757,931.8057605514581,820.3477700533443,596.191216687409,599.3182218072803,861.464556594879,166.9597494171383,686.6173789107579},
    {135.94821543926025,200.69688995277338,102.58373186766738,727.1505345514572,193.9979472418483,209.58872380424447,702.8719493907016,713.498911703551,932.4714245682458,823.1652111352774}};

    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;
}
$\endgroup$
  • $\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.