I tried to run very simple example of connecting to WSTP. I checked a few links in this site but none of them could resolved my issue. I added three .lib files to visual studio location from this link and also linked to my program on visual studio. Also i did it for wstp.h and .exe. each one as explained in documentation developer tutorial. I modified the linker on C++ project and added all these files to current project on visual studio. But still i am getting this problem. I wish they had better documentation. Can someone help me , thanks
error LNK2019: unresolved external symbol _WSInitialize
error LNK2019: unresolved external symbol _WSDeinitialize
error LNK2019: unresolved external symbol _WSOpenString
error LNK2019: unresolved external symbol _WSClose

#include "wstp.h"
using namespace std;
int main()
    WSENV env;
    WSLINK link;
    int error;

    env = WSInitialize((WSEnvironmentParameter)0);
    if (env == (WSENV)0)
    { /* unable to initialize WSTP environment */

    link = WSOpenString(env, "/usr/local/bin/math -mathlink", &error);
    if (link == (WSLINK)0 || error != WSEOK)
    { /* unable to create link to the Kernel */

    /* ... */


    return 0;

EDITED Solved: beside the right answer, i should have compile as x64 because my system is 64bit, but i ran the program as x86 and got those errors


1 Answer 1


Those particular linker errors mean that the input library was not added under the linker settings. I put together an example project on GitHub that you can use for reference. The paths are currently setup for the default installation location for Mathematica 12.2.

  • $\begingroup$ that really helped me, one more mistake which i did, I compiled the code as x86 but my system is 64 bits, so i had to change it to x64. thanks $\endgroup$
    – Azzurro94
    Mar 3, 2021 at 14:50
  • $\begingroup$ could you tell me what should be instead of -mathlink? is that mathlink.exe? thanks $\endgroup$
    – Azzurro94
    Mar 3, 2021 at 15:06
  • $\begingroup$ In newer versions, -wstp is preferred. But -mathlink still exists for compatibility reasons. $\endgroup$
    – ihojnicki
    Mar 3, 2021 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.