I am trying to call and run the C++ code at the bottom of this post which must be stored in a file called poissonvariate.cpp. I am getting the following error message which I will display here before discussing how I got to this point.
"Compile error: !(\"clang: error: invalid deployment target for \ -stdlib=libc++ (requires OS X 10.7 or later)\")"
I am running OS X 10.7.4 with XCode 4.5.1 so somewhere a flag is set to 10.6.x or earlier and for some reason Mathematica is finding it. On the command line I can compile and run code with clang++ without difficulty. The same error message is reported here which has nothing to do with Mathematica: https://stackoverflow.com/questions/24243176/how-to-specify-target-mac-os-x-version-using-qmake
I found this line of code in a python config.log file: CONFIGURE_MACOSX_DEPLOYMENT_TARGET='10.3' .
I think this is set with Xcode for application developers but I'm not sure? How to set deployment TARGET TO 10.7?
The C++ code I want to run was originally discussed here: Can Mathematica's random number generation be improved? . The library that the c++ provides can be created with the code below. (If you want to actually run the code go to the link and scroll down to blochwave's answer and grab the lines of code needed to run it.)
Needs["CCodeGenerator`"]
Needs["CCompilerDriver`"]
Needs["SymbolicC`"]
PoissonVariateLib = CreateLibrary[{ToString[NotebookDirectory[]] <>
"poissonvariate.cpp"}, "PoissonVariateLib", "Debug" -> False, "CompileOptions" -> "-std=c++11 -O3"];
The errors that I get on Macs occur in the call to CreateLibrary . After playing around a little I came up with this line:
PoissonVariateLib = CreateLibrary[{ToString[NotebookDirectory[]] <> "poissonvariate.cpp"}, "PoissonVariateLib", "Debug" -> False, "LibraryDirectories" -> "/usr/bin/../lib/clang/4.1", "IncludeDirectories" -> "/usr/lib/c++/v1","CompileOptions" -> "-std=c++11 -stdlib=libc++ -O3", "CompilerInstallation" -> "/usr/bin/clang++"];
which I had hoped would work. As stated above I am running Mac OS X 10.7.4 with XCode 4.5.1 .
Execution of this line generates the invalid deployment target error at the top of this post.
---------------The C++ code------------------------------------
#include "WolframLibrary.h"
#include "stdio.h"
#include "stdlib.h"
#include <random>
#include <chrono>
EXTERN_C DLLEXPORT mint WolframLibrary_getVersion(){return WolframLibraryVersion;}
EXTERN_C DLLEXPORT int WolframLibrary_initialize( WolframLibraryData libData) {return 0;}
EXTERN_C DLLEXPORT void WolframLibrary_uninitialize( WolframLibraryData libData) {}
EXTERN_C DLLEXPORT int BinomialVariate(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res){
int err; // error code
MTensor m1; // input tensor 2
MTensor m2; // input tensor 2
MTensor m3; // output tensor
mint const* dims1; // dimensions of the tensor
double* data1; // actual data of the input tensor
double* data2;
double* data3; // data for the output tensor
mint i; // bean counters
m1 = MArgument_getMTensor(Args[0]);
dims1 = libData->MTensor_getDimensions(m1);
m2 = MArgument_getMTensor(Args[1]);
err = libData->MTensor_new(MType_Real, 1, dims1, &m3);
data1 = libData->MTensor_getRealData(m1);
data2 = libData->MTensor_getRealData(m2);
data3 = libData->MTensor_getRealData(m3);
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 generator (seed); // RNG
for(i=0;i<dims1[0];i++) {
std::binomial_distribution<int> distribution(data1[i], data2[i]);
data3[i] = distribution(generator);
}
MArgument_setMTensor(Res, m3);
return LIBRARY_NO_ERROR;
}