Log in

View Full Version : Compling PinTools with Microsoft Visual Studio (MSVC9)


Piotr Bania Chronicles
June 4th, 2011, 13:17
After hearing some good reviews about Pin DBI framework ("http://www.pintool.org/") I have decided to give it a chance. I have downloaded the version for MSVC9 and tried to compile a sample project with MSVC9. That was the point where my problems started. Actually there is very minimal amount of information at the Pin website regarding using it with Microsoft Visual Studio (and the sample project file is pretty useless). Of course I have built the sample tools with "nmake" command successfully but I wanted to do the same straight from my MSVC. So I have spent line an hour (or two) fighting with massive numbers of compiler, linker (unresolved externals) errors until the build was done correctly. Surprisingly after running Pin with my PinTool it returned another error: "Pin 2.9 kit 39586E: Failed to load tool DLL. System error: Unknown error.". Well at this point I'm still not really sure what was wrong but after doing a lot of trial and error tests I have managed to create a MSVC configuration that actually works (at least for me). So here it is maybe someone will find it helpful. (Please note it may contain some redundant switches but it should be good enough for a start point.) For release configuration simply remove the "\DEBUG" switches.


So here are the steps:
"E:\pin" is the pin base directory.

Include directories:
E:\pin\extras\components\include\
E:\pin\extras\xed2-ia32\include
E:\pin\source\include\gen
E:\pin\source\include
http://piotrbania.com/all/__blah/blog_pin/include_dirs.png ("http://piotrbania.com/all/__blah/blog_pin/include_dirs.png")

Library directories:
E:\pin\ia32\lib-ext
E:\pin\extras\xed2-ia32\lib
E:\pin\ia32\lib
http://piotrbania.com/all/__blah/blog_pin/library_dirs.png ("http://piotrbania.com/all/__blah/blog_pin/library_dirs.png")

Preprocessor Definitions
:
TARGET_IA32;HOST_IA32;TARGET_WINDOWS;USING_XED
http://piotrbania.com/all/__blah/blog_pin/preprocessor.png ("http://piotrbania.com/all/__blah/blog_pin/preprocessor.png")

Compiler options:
/MT /EHs- /EHa- /wd4530 /DTARGET_WINDOWS /DBIGARRAY_MULTIPLIER=1
/DUSING_XED /D_CRT_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /nologo /DTARGET_IA32 /DHOST_IA32
http://piotrbania.com/all/__blah/blog_pin/compiler_options.png ("http://piotrbania.com/all/__blah/blog_pin/compiler_options.png")

Linker options:
/DLL /EXPORT:main /NODEFAULTLIB /NOLOGO /ENTRY:Ptrace_DllMainCRTStartup@12 ntdll-32.lib libxed.lib pin.lib pinvm.lib libcmt.lib libcpmt.lib /DEBUG
http://piotrbania.com/all/__blah/blog_pin/linker_options.png ("http://piotrbania.com/all/__blah/blog_pin/linker_options.png")


Who knows maybe this will work for you https://blogger.googleusercontent.com/tracker/5498266518143777458-6697097767879408941?l=blog.piotrbania.com


http://blog.piotrbania.com/2011/06/compling-pintools-with-microsoft-visual.html