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)
$(PIN_ROOT)\source\include\pin;$(PIN_ROOT)\source\include\pin\gen;$(PIN_ROOT)\source\tools\InstLib;$(PIN_ROOT)\extras\xed-intel64\include\xed;$(PIN_ROOT)\extras\components\include;$(PIN_ROOT)\extras\stlport\include;$(PIN_ROOT)\extras;$(PIN_ROOT)\extras\libstdc++\include;$(PIN_ROOT)\extras\crt\include;$(PIN_ROOT)\extras\crt;$(PIN_ROOT)\extras\crt\include\arch-x86;$(PIN_ROOT)\extras\crt\include\kernel\uapi;$(PIN_ROOT)\extras\crt\include\kernel\uapi\asm-x86;
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
$(PIN_ROOT)\intel64\lib;$(PIN_ROOT)\intel64\lib-ext;$(PIN_ROOT)\extras\xed-intel64\lib;$(PIN_ROOT)\intel64\runtime\pincrt;
and these libraries, in the absolutest correct order (/NODEFAULTLIB
is recommended)
pin.lib;xed.lib;pinvm.lib;kernel32.lib;pincrt.lib;ntdll-64.lib;crtbeginS.obj
(stlport-static.lib
, m-static.lib
, c-static.lib
and 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.