Sunday, 4 January 2015

Error C1189 when using OSIsoft PI API with C++ standard libraries

It can be frustrating to get libraries to work together, especially old ones. Yes, I know the PI API will be deprecated sometime in the future, but it is so much easier to set up and use. Unfortunately, when you try to include C++ standard libraries such as <string>, errors spew out...

Error    3    error C1189: #error :  The C++ Standard Library forbids macroizing keywords. Enable warning C4005 to find the forbidden macro.    c:\program files (x86)\microsoft visual studio 12.0\vc\include\xkeycheck.h    250    1    ....

With a little digging in the header files, the offending lines can be found in pidefs.h:

/* Following is to support MFC Version 4.2 Delivered with Visual C++ 4.2 */
#ifndef linux
#if !defined(_MFC_VER) || (_MFC_VER < 0x420)
#define true           ((pibool)1)
#define false          ((pibool)0)
#endif
#endif


So, for a quickfix, simply comment out the lines #define true and #define false.

No comments:

Post a Comment