0
$\begingroup$

Edited I am trying to run a C++ program on Visual Studio. this program needs to connect to mathematica kernel. assume any simple program, no matters. something like this code. I added and linked wstp64i4.dll, wstp64i4m.lib, wstp64i4s.lib and wstp64i4.lib.

env = WSInitialize((char*)0);
if (env == (WSENV)0)
{
    printf("unable to initialize environment");
}

ml = WSOpenString(env, "-linkname \"C:/Program Files/Wolfram Research/Mathematica/10.4/MathKernel.exe -mathlink\"", &error);

This program starts fine on RELEASE MODE on Visual studio but NOT on Debug mode. I really need to start it on debug mode. When I start on debug it shows me lots of error, one of the errors : (Again the code works fine on Release mode so i think there is no problem with these two lines of code)

Error LNK2005 "public: virtual __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::~basic_streambuf<char,struct std::char_traits<char> >(void)" (??1?$basic_streambuf@DU?$char_traits@D@std@@@std@@UEAA@XZ) already defined in wstp64i4s.lib(mlservicediscovery.obj) FxDomain E:\ProgrammingProjects\PhD\FxDomain\FxDomain\msvcprtd.lib(MSVCP140D.dll)

$\endgroup$
6
  • 1
    $\begingroup$ In order for this to be answerable, you would need to describe what you are doing, what you expect to happen, and what happens instead, in much greater detail. Preferably provide a minimal example. Note that without these improvements, the question is very likely to be closed, for the simple reason that without more information people can only guess about not only what the problem is, but also about what you were doing ... $\endgroup$ – Szabolcs Mar 24 at 15:08
  • $\begingroup$ thanks I really dont know what information you mean, I will provide definitely. ok I edited the problem but the whole story is very simple c++ program which tries to connect to mathematica kernel, runs on release mode but not on debug mode. $\endgroup$ – Azzurro94 Mar 24 at 15:34
  • $\begingroup$ See here for guidance: sscce.org If you provide a minimal example, it will save having to ask many avoidable questions. "the whole story is very simple" <- In that case a minimal example will be easy to construct. $\endgroup$ – Szabolcs Mar 24 at 15:37
  • 1
    $\begingroup$ This is still far from a complete example and does not follow the guidelines I gave you. If you keep it like this, your chances of a useful answer are reduced. There is no complete program and no comments on how you compiled the program (compilation and linking flags, etc.) $\endgroup$ – Szabolcs Mar 24 at 15:58
  • 1
    $\begingroup$ However, now we can see that you are using WSTP (which you did not say) that you receive an error when linking (you said you saw errors when running an presumably successfully compiled/linked program). You say you link to wstp64i4m.dll, wstp64i4s.dll, but there are no such files. These are .lib, not DLL. You should link to one copy of the library, probably the import library wstp64i4m.lib (I don't know if you also have to add wstp64i4.dll, as I don't actually use the VS GUI). The problem is likely trying to link to multiple different copies. $\endgroup$ – Szabolcs Mar 24 at 16:04
3
$\begingroup$

Do not link against wstp64i4s.lib. wstp64i4.lib is the only version you should use.

$\endgroup$
7
  • $\begingroup$ Is wstp64i4s.lib the static version? What is the difference between wstp64i4.lib and wstp64i4m.lib? The docs use only the latter. $\endgroup$ – Szabolcs Mar 24 at 18:34
  • $\begingroup$ Yes the "s" version is a static library. That variant has a number of asterisks associated with it (at times I regret even asking for it). The "m" is the same as the wstp64i4. I'm not sure why that was carried over to the wstp version (because compatibility with previous versions was not necessary). $\endgroup$ – ihojnicki Mar 24 at 19:01
  • $\begingroup$ fantastic. that was right, thanks a lot, by the way I followed the installation document which says copy paste all those files so i thought i have to link to all, $\endgroup$ – Azzurro94 Mar 24 at 21:36
  • $\begingroup$ The documentation uses only the "m" version: reference.wolfram.com/language/tutorial/… Was there a difference between the "m" and plain versions for the "ml" libraries? $\endgroup$ – Szabolcs Mar 24 at 21:37
  • 1
    $\begingroup$ @Azzurro94, no problem. Toolchain setup is always difficult the first time around. Lots of places to trip up and you have get used to reading the tea leaves that are linker error messages. $\endgroup$ – ihojnicki Mar 25 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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