In the compile process of a C function written by using wstp.h library (Mathematica 11.3), an error (Error LNK2019: unresolved external symbol WSEvaluate referenced in function) is shown.
I opened wstp.h file. For each function started by WS, there is an ML equivalent (For example, #define MLGetData WSGetData), but for WSEvaluate there is nothing. I added a line- #define MLEvaluate WSEvaluate- but it did not work. Can you please guide me to solve this compile error?
Here is a C fucntion which produces the mentioned error:
#include "wstp.h"
#include <stdlib.h>
#include <windows.h>
extern int WSMain(int, char **);
#ifdef WINDOWS_WSTP
extern HWND WSInitializeIcon(HINSTANCE hinstCurrent, int nCmdShow);
#endif
extern void ShowMyMessages();
void ShowMyMessages()
{
WSEvaluate(stdlink, "Message[ShowMyMessages::msg]");
WSNextPacket(stdlink);
WSNewPacket(stdlink);
WSPutSymbol(stdlink, "$Failed");
}
#if WINDOWS_WSTP
int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, LPSTR lpszCmdLine, int nCmdShow)
{
char buff[512];
char FAR * buff_start = buff;
char FAR * argv[32];
char FAR * FAR * argv_end = argv + 32;
hinstPrevious = hinstPrevious; /* suppress warning */
if (!WSInitializeIcon(hinstCurrent, nCmdShow)) return 1;
WSScanString(argv, &argv_end, &lpszCmdLine, &buff_start);
return WSMain((int)(argv_end - argv), argv);
}
#else
int main(int argc, char* argv[])
{
return WSMain(argc, argv);
}
#endif
And here is its .tm code
void ShowMyMessages P(());
:Begin:
:Function: ShowMyMessages
:Pattern: ShowMyMessages[]
:Arguments: {}
:ArgumentTypes: {}
:ReturnType: Manual
:End:
:Evaluate: ShowMyMessages::msg = "Hello"
:Evaluate: ShowMyMessages::usage = "ShowMyMessages[]"
And here its compile commands
SET CL=/nologo /c /DWIN32 /D_WINDOWS /W3 /O2 /DNDEBUG
SET LINK=/NOLOGO /SUBSYSTEM:windows /INCREMENTAL:no /PDB:NONE kernel32.lib user32.lib gdi32.lib
WSPREP showMessage.tm -o showMessagetm.c
CL showMessage.c showMessagetm.c
LINK showMessage.obj showMessagetm.obj wstp64i4m.lib /OUT:showMessage.exe
This is the message generated by the compiler:
showMessage.obj : error LNK2019: unresolved external symbol WSEvaluate referenced in function ShowMyMessages
showMessage.exe : fatal error LNK1120: 1 unresolved externals
wsprepprogram from a.tmfile. It would seem that you are not linkingwsprep's output into your program. – Szabolcs Sep 06 '18 at 06:52objdump -tC libWSTP64i4.so | grep WSEvaluateyields nothing. – kh40tika Sep 06 '18 at 07:07wsprep/mprep. It's not supposed to be present in that library. It is generated bymprep(you can see it in the code generated bymprep). – Szabolcs Sep 06 '18 at 07:43