I'm currently using WolframLibraryData::Message
to generate messages from a library function, like this:
Needs["CCompilerDriver`"]
src = "
#include \"WolframLibrary.h\"
DLLEXPORT mint WolframLibrary_getVersion() {return WolframLibraryVersion;}
DLLEXPORT int WolframLibrary_initialize(WolframLibraryData libData) {return 0;}
DLLEXPORT void WolframLibrary_uninitialize(WolframLibraryData libData) {}
DLLEXPORT myFunc(WolframLibraryData libData, mint argc, MArgument* args, MArgument result)
{
libData->Message(\"Here's my message\");
MArgument_setReal(result,1.1);
return LIBRARY_NO_ERROR;
}
";
lib = CreateLibrary[src, "mylib"];
myFunc = LibraryFunctionLoad[lib, "myFunc", {}, Real];
Now the problem can be seen if myFunc[]
is called. I get this result:
LibraryFunction::Here's my message: -- Message text not found -- >>
1.1
The problem is this -- Message text not found --
part. Apparently I'm generating the message in a wrong way. So how should I do instead? How do I fill this "message text" to make it look like messages from normal Mathematica functions?
Message()
allows for. Setting up a framework to make this easy is going to take a bit of work. In practical situations the approach I'm taking is to leave this sort of thing (checking errors, issuing user-friendly messages, etc.) to Mathematica code--not C code--as much as possible. $\endgroup$