Carlos's answer is more of a workaround, but it's so much spot on. Getting all the right knobs right is an insane job. And even more so with version 3 that switched away from whatever native runtime the OS may have, and started to use their own.
After half a day reversing the examples, I could come up with this (I'm assuming a 64 bit Windows target, but it shouldn't be difficult to notice what's architecture specific)
First of all you should get the include folders right (make sure to set PIN_ROOT in the first place though)
Then, set these flags in the compiler:
/MT /GR- /GS- /EHs- /EHa- /fp:strict /Oi- /FIinclude/msvc_compat.h
And these defines for the preprocessor:
TARGET_IA32E;HOST_IA32E;TARGET_WINDOWS;WIN32;__PIN__=1;PIN_CRT=1;__LP64__ (please, really pay attention to the first two.. IA32E means x86-64 and their wrong combination can lead to countless ungodly issues with symbols and whatnot).
Remember that with the exception of like 3 headers ([xmm]intrin.h and somewhat limitedly windows.h) you cannot use any other one outside of pintool.
Next there is the linker. You need these folders
and these libraries, in the absolutest correct order (
/NODEFAULTLIB is recommended)
os-apis.lib may also be needed in more complex situations)
Last but not least, you should add
/export:main /SAFESEH:NO /IGNORE:4210 /IGNORE:4049 to the linker command line. For anything else give a check to the PinCRT whitepaper, whose reading I cannot recommend enough.