I tried to create my own C function, compile as a dll and link it to Mathematica.
For my first steps I used an example from the help, but it was wrong...
My C code is
#include "c:\Program Files\Wolfram Research\Mathematica\9.0\SystemFiles\IncludeFiles\C\WolframLibrary.h"
DLLEXPORT mint WolframLibrary_getVersion( )
{
return WolframLibraryVersion;
}
DLLEXPORT int WolframLibrary_initialize( WolframLibraryData libData)
{
return 0;
}
DLLEXPORT int demo_I_I(WolframLibraryData libData,
mint Argc, MArgument *Args, MArgument Res) {
mint I0;
mint I1;
I0 = MArgument_getInteger(Args[0]);
I1 = I0 + 1;
MArgument_setInteger(Res, I1);
return LIBRARY_NO_ERROR;
}
After compilation (using Codeblocs and mingw32-g++.exe) with 0 errors and 0 warnigs the result is a .dll file called
knihovna-1.dllIn Mathematica is my code
In[14]:= FindLibrary["C:\\Users\\Tom\\Dropbox\\MathematicaC\\knihovna-1\\bin\\knihovna-1"]
Out[14]= "C:\\Users\\Tom\\Dropbox\\MathematicaC\\knihovna-1\\bin\\knihovna-1.dll"
In[15]:= LibraryFunctionLoad["C:\\Users\\Tom\\Dropbox\\MathematicaC\\knihovna-1\\bin\\knihovna-1", "demo_I_I", {Integer}, Integer]
In[15]:= LibraryFunction::libload: The function demo_I_I was not loaded from the file C:\Users\Tom\Dropbox\MathematicaC\knihovna-1\bin\knihovna-1.dll. >>
Out[15]= $Failed
I seems, my poor undestandig how to link a library is not poor, but totaly wrong...
Please, it is possible to tell me shortly, what I am doing wrong and ho to make i correct?
Thanks!