Search code examples
c++visual-studiolinkerunresolved-externaldetours

How to include Microsoft detours library in visual studio


I am trying to use the detours library in a visual studio empty windows project. I cloned the repository (https://github.com/microsoft/Detours), I added the include directory into Project Properties / C/C++ / Additional Include Directories, and I added the lib.X86 directory into Project Properties / Linker / Additional Library Directories. I get no errors visible on the file, but when I build I get

1>Source.cpp
1>Source.obj : error LNK2019: unresolved external symbol _DetourTransactionBegin@0 referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _DetourTransactionCommit@0 referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _DetourUpdateThread@4 referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _DetourAttach@8 referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _DetourDetach@8 referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _DetourRestoreAfterWith@0 referenced in function _main
1>C:\Users\colel\source\repos\Project3\Debug\Project3.exe : fatal error LNK1120: 6 unresolved externals
1>Done building project "Project3.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =========

Which looks like the library wasn't included correctly. How do I properly include the detours library into a visual studio project and what am I doing wrong?


Solution

  • You need to add the specific .lib file, which I'm guessing is "detours.lib" (or similar) to the "Additional Dependencies" line.

    Properties->Linker->Input->Additional Dependencies.

    enter image description here