5 link to excellent tutorial edited Jun 14 '17 at 15:36 Szabolcs 172k1818 gold badges468468 silver badges10001000 bronze badges Update: I posted a tutorial series on LibraryLink at Wolfram Community. Here is my pitch to use LibraryLink, which is a really nice new technology in version 8. I am not going to pretend this is easy by any stretch of the imagination, because it involves a decent amount of knowledge of both Mathematica and C compilers. In this particular case I am using Visual Studio C++ Express plus the Microsoft Windows SDK 7.1. For the record, I had quite a bit of help from Joel Klein with this answer. Here is my pitch to use LibraryLink, which is a really nice new technology in version 8. I am not going to pretend this is easy by any stretch of the imagination, because it involves a decent amount of knowledge of both Mathematica and C compilers. In this particular case I am using Visual Studio C++ Express plus the Microsoft Windows SDK 7.1. For the record, I had quite a bit of help from Joel Klein with this answer. Update: I posted a tutorial series on LibraryLink at Wolfram Community. Here is my pitch to use LibraryLink, which is a really nice new technology in version 8. I am not going to pretend this is easy by any stretch of the imagination, because it involves a decent amount of knowledge of both Mathematica and C compilers. In this particular case I am using Visual Studio C++ Express plus the Microsoft Windows SDK 7.1. For the record, I had quite a bit of help from Joel Klein with this answer. 4 replaced http://stackoverflow.com/ with https://stackoverflow.com/ edited May 23 '17 at 12:35 Here is my pitch to use LibraryLink, which is a really nice new technology in version 8. I am not going to pretend this is easy by any stretch of the imagination, because it involves a decent amount of knowledge of both Mathematica and C compilers. In this particular case I am using Visual Studio C++ Express plus the Microsoft Windows SDK 7.1. For the record, I had quite a bit of help from Joel KleinJoel Klein with this answer. Here is my pitch to use LibraryLink, which is a really nice new technology in version 8. I am not going to pretend this is easy by any stretch of the imagination, because it involves a decent amount of knowledge of both Mathematica and C compilers. In this particular case I am using Visual Studio C++ Express plus the Microsoft Windows SDK 7.1. For the record, I had quite a bit of help from Joel Klein with this answer. Here is my pitch to use LibraryLink, which is a really nice new technology in version 8. I am not going to pretend this is easy by any stretch of the imagination, because it involves a decent amount of knowledge of both Mathematica and C compilers. In this particular case I am using Visual Studio C++ Express plus the Microsoft Windows SDK 7.1. For the record, I had quite a bit of help from Joel Klein with this answer. 3 added 121 characters in body edited Jul 3 '16 at 14:50 xyz 27033 gold badges2727 silver badges100100 bronze badges Here is my pitch to use LibraryLink, which is a really nice new technology in version 8. I am not going to pretend this is easy by any stretch of the imagination, because it involves a decent amount of knowledge of both Mathematica and C compilers. In this particular case I am using Visual Studio C++ ExpressVisual Studio C++ Express plus the Microsoft Windows SDK 7.1Microsoft Windows SDK 7.1. For the record, I had quite a bit of help from Joel Klein with this answer.MathematicaMathematica sidemyLibrary = CreateLibrary[ CreateLibrary[{"c:\\users\\arnoudb\\myLibrary.c"}, "myLibrary", "Debug" -> False]; myFunction = LibraryFunctionLoad[ myLibraryLibraryFunctionLoad[myLibrary, "myFunction", {{Real, 2}}, {Real, 2}]; #include "WolframLibrary.h" DLLEXPORT mint WolframLibrary_getVersion(){return WolframLibraryVersion;} DLLEXPORT int WolframLibrary_initialize( WolframLibraryData libData) {return 0;} DLLEXPORT void WolframLibrary_uninitialize( WolframLibraryData libData) {} #include "WolframLibrary.h" DLLEXPORT mint WolframLibrary_getVersion(){return WolframLibraryVersion;} DLLEXPORT int WolframLibrary_initialize( WolframLibraryData libData) {return 0;} DLLEXPORT void WolframLibrary_uninitialize( WolframLibraryData libData) {} DLLEXPORT int myFunction(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res){ int err; // error code MTensor m1; // input tensor MTensor m2; // output tensor mint const* dims; // dimensions of the tensor double* data1; // actual data of the input tensor double* data2; // data for the output tensor mint i; // bean counters mint j; DLLEXPORT int myFunction(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res){ int err; // error code MTensor m1; // input tensor MTensor m2; // output tensor mint const* dims; // dimensions of the tensor mreal *data1; // actual data of the input tensor mreal *data2; // data for the output tensor mint i; // bean counters mint j;  m1 = MArgument_getMTensor(Args[0]); dims = libData->MTensor_getDimensions(m1); err = libData->MTensor_new(MType_Real, 2, dims,&m2); data1 = libData->MTensor_getRealData(m1); data2 = libData->MTensor_getRealData(m2);  m1 = MArgument_getMTensor(Args[0]); dims = libData->MTensor_getDimensions(m1); err = libData->MTensor_new(MType_Real, 2, dims,&m2); data1 = libData->MTensor_getRealData(m1); data2 = libData->MTensor_getRealData(m2);  for(i=0;i False]; myFunction = LibraryFunctionLoad[ myLibrary, "myFunction", {{Real, 2}}, {Real, 2}]; #include "WolframLibrary.h" DLLEXPORT mint WolframLibrary_getVersion(){return WolframLibraryVersion;} DLLEXPORT int WolframLibrary_initialize( WolframLibraryData libData) {return 0;} DLLEXPORT void WolframLibrary_uninitialize( WolframLibraryData libData) {} DLLEXPORT int myFunction(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res){ int err; // error code MTensor m1; // input tensor MTensor m2; // output tensor mint const* dims; // dimensions of the tensor double* data1; // actual data of the input tensor double* data2; // data for the output tensor mint i; // bean counters mint j;  m1 = MArgument_getMTensor(Args[0]); dims = libData->MTensor_getDimensions(m1); err = libData->MTensor_new(MType_Real, 2, dims,&m2); data1 = libData->MTensor_getRealData(m1); data2 = libData->MTensor_getRealData(m2);  for(i=0;i False]; myFunction = LibraryFunctionLoad[myLibrary, "myFunction", {{Real, 2}}, {Real, 2}]; #include "WolframLibrary.h" DLLEXPORT mint WolframLibrary_getVersion(){return WolframLibraryVersion;} DLLEXPORT int WolframLibrary_initialize( WolframLibraryData libData) {return 0;} DLLEXPORT void WolframLibrary_uninitialize( WolframLibraryData libData) {} DLLEXPORT int myFunction(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res){ int err; // error code MTensor m1; // input tensor MTensor m2; // output tensor mint const* dims; // dimensions of the tensor mreal *data1; // actual data of the input tensor mreal *data2; // data for the output tensor mint i; // bean counters mint j;  m1 = MArgument_getMTensor(Args[0]); dims = libData->MTensor_getDimensions(m1); err = libData->MTensor_new(MType_Real, 2, dims,&m2); data1 = libData->MTensor_getRealData(m1); data2 = libData->MTensor_getRealData(m2);  for(i = 0; i < dims[0]; i++) { for(j = 0; j < dims[1]; j++) { data2[i*dims[1]+j] = data1[i*dims[1]+j]*data1[i*dims[1]+j]; } }  MArgument_setMTensor(Res, m2); return LIBRARY_NO_ERROR; }  2 deleted 141 characters in body edited Oct 9 '15 at 18:47 Arnoud Buzing 7,89522 gold badges3131 silver badges5050 bronze badges Post Migrated Here from stackoverflow.com occurred Jul 18 '12 at 11:42 1 answered Nov 15 '11 at 23:16 Arnoud Buzing 7,89522 gold badges3131 silver badges5050 bronze badges