Rhino C++: StdAfx.h Interfering with Other Libraries

Hello,

I am trying to use exprtk.hpp with a C++ plugin and am unable to figure out why stdafx.h doesn’t like that. All I want to do is #include “exprtk.hpp” in the cmdPluginName.cpp file, but then I get a whole bunch of errors such as “unrecognizable template declaration/definition” for various functions in the library. I know stdafx.h is the issue because I placed exprtk.hpp in a custom header file and it compiled fine - up until I tried to include that custom header file in cmdPluginName.cpp, to which the errors returned.

Ideally, I’d like to include exprtk.hpp in the custom header file (as well as rhinoSdkApp.h) and then include that header in cmdPluginName.cpp. This is my first time using stdafx.h in any project, so I’m sure there’s something missing with my understanding in how all this works. Thank you for any advice in solving this issue!

Edit: this seems to have to do something with Windows libraries and macros. The errors are mostly on lines that have std::min/max in exprtk.hpp.

image

I figured out a solution, posting it here in case others come across this issue. Taken from this question, I modified stdafx.h to include the following:

#if defined(_M_X64) && defined(WIN32) && defined(WIN64)
//  The afxwin.h includes afx.h, which includes afxver_.h, 
//  which unconditionally defines WIN32  This is a bug.
//  Note, all Windows builds (32 and 64 bit) define _WIN32.
//  Only 64-bit builds define _WIN64. Never define/undefine
// _WIN32 or _WIN64.  Only define EXACTLY one of WIN32 or WIN64.
//  See the MSDN "Predefined Macros" help file for details.
#undef WIN32
#define NOMINMAX	// my additions
#undef min			// my additions
#undef max			// my additions
#endif