# Where to place the essential WSTP files in Visual Studio 2019?

I have Visual Studio for C installed in : C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC

"Copy wstp.h to C:\Program Files\Microsoft Visual Studio 11\VC\include." - I have no include directory below C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC

"Copy the files wstp32i4.lib, wstp32i4m.lib, and wstp32i4s.lib to C:\Program Files\Microsoft Visual Studio 11\VC\lib. Note that for 64-bit Windows systems, these files will be named wstp64i4*." - I have no lib directory below C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC

"Finally, copy wsprep.exe to C:\Program Files\Microsoft Visual Studio 11\VC\bin." - I have no bin directory below C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC

I basically would like to know how to use WSTP with Visual Studio 2019, starting with how to place the above mentioned three required files.

Additionally, there is also a mention of a file wstpi64.lib, where do I have to place this file?

• I have not used the VS GUI with MathLink, but in principle, what you need to do is simple: mathlink.h/wstp.h must be on the include path; the .lib files must be on the library path, and must be linked to; the .dll files must be on the PATH—this should always be the case if the installable MathLink program is launched directly from Mathematica. Now you just need to figure out how to change these paths for any given system (either command line of GUI). mprep/wsprep are needed to convert the .tm files into .c course. You can run this tool directly. – Szabolcs Oct 14 '20 at 13:54
• Generally, there is no need to copy anything anywhere. All you need to ensure if that the compiler/linker find the necessary files, and you include the appropriate .lib files when linking the final executable. – Szabolcs Oct 14 '20 at 13:55
• Thank you for your reply @Szabolcs - I will proceed with this, and might come back with many more "newbie WSTP questions." - I now have at least 3 months fulltime free to make a start with connecting Mathematica to either Pari*GP or GAP. It is time to get this finally done. But I might need a lot of input from you guys. – nilo de roock Oct 14 '20 at 14:00
• IMO, the steps suggested by the docs are an anti-pattern. At one point in time, I made a property sheet for MathLink and WSTP, which simplified configuration down to just "add this property sheet to each configuration". I'll have to look for it and post it somewhere if I find it. – ihojnicki Oct 14 '20 at 17:04
• Looking forward to that. – nilo de roock Oct 15 '20 at 6:37

The easiest way is probably to use a set of property sheets. I posted a set here on GitHub that you can try out.

• I will definitely try this out. – nilo de roock Oct 17 '20 at 9:17
• Could you please add to your answer the steps to pre-process, compile and run Addtwo from within Visual Studio? – nilo de roock Oct 17 '20 at 9:24

Although file placements in Microsoft directories is ill advised to some here, it is what the Wolfram Documentation recommends. Sadly the current Wolfram Documentation (12.1.1) is not on par with Visual Studio 2019.

For Visual Studio 2019:

The wstp.h file MUST be placed in

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\VS\include


The wstp64i4.lib file should be placed in

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.25.28610\bin\Hostx64\x64


The wsprep.exe file should be placed in

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.25.28610\bin\Hostx64\x64


The wstp64i4.dll file should be placed in

C:\Windows\System32


Directory names might alter slightly per Visual Studio 2019 version / build.

With these settings you can either work with the MSFC tools from the command line or from within Visual Studio 2019.

• There should be a setting for the include file search path. With gcc/clang this is the -I option. With the Microsoft compiler, it's /I. My point is that there is no need to copy files—you need to find the setting for the include path in the VS GUI. I don't use the graphical interface, so I don't know where it is. – Szabolcs Oct 16 '20 at 10:54
• Copying these files is not a good idea IMO. Eventually, you will install a new version of Mathematica, which comes with a different wstp.h, and you will forget to copy the new file. Or you might have two versions of Mathematica installed, and you might want the ability to compile with either. This is why setting the include path is the much better option. – Szabolcs Oct 16 '20 at 10:56
• I'll have another look at it. But mind that the Wolfram documentation recommends copying. – nilo de roock Oct 16 '20 at 11:46
• @Szabolcs, I'll just go ahead and say it. Copying them into VS's layout is a bad idea. Always has been. – ihojnicki Oct 16 '20 at 13:07