# cannot launch the Visual Studio C++ Mathematica program on debug mode, only on release mode!

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)

• 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 ... – Szabolcs Mar 24 at 15:08
• 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. – Azzurro94 Mar 24 at 15:34
• 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. – Szabolcs Mar 24 at 15:37
• 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.) – Szabolcs Mar 24 at 15:58
• 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. – Szabolcs Mar 24 at 16:04

• Is wstp64i4s.lib the static version? What is the difference between wstp64i4.lib and wstp64i4m.lib? The docs use only the latter. – Szabolcs Mar 24 at 18:34