Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1>LINK : fatal error LNK1104: cannot open file 'detours.lib' --> Issue while Building #322

Open
AbishekPonmudi opened this issue Oct 6, 2024 · 1 comment
Labels

Comments

@AbishekPonmudi
Copy link

While developing an EDR, I encountered an issue when working with kernel32.dll and user32.dll for inline hooking using the CreateFileW API. This is not the main problem, as my issue occurs during the build process.

Build started at 09.11 PM...
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug x64 ------
1>ConsoleApplication1.cpp
1>LINK : fatal error LNK1104: cannot open file 'detours.lib'
1>Done building project "ConsoleApplication1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 09.11 PM and took 01.273 seconds ==========

Does anyone have a solution for how to fix this issue?

@ShadowKnightMK4
Copy link

ShadowKnightMK4 commented Oct 17, 2024

Hi, I'm not sure if you're still encountering this issue, but I've had similar ones before. Here's a general fix that I used.
I hope you're using Visual Studio 2022, as that's what I'm familiar with, but I believe the process for Visual Studio Code is gonna be similar.

In short, your console app isn't finding the static library you're trying to include.

If you're looking for a quick fix and you've already built Detours as a static library, insert the following line into your console app's source code. Replace 'X' with the full path to your built Detours static library, enclosed in a C-style quoted string. This instructs the compiler to include this library in the build.

#pragma comment (lib, "X")

I also recommend setting your solution to build Detours before your console app. In Visual Studio 2022, you can set build dependencies in the project menu for the project in question. This should get you back up and running.

A better long-term solution would be to learn some of the macros and set the library paths in your console app to find the Detours version you're using based on config (Debug/ Release). For instance, if Detours compiles and outputs to "$(SolutionDir)\builds\Detours$(Config)\x64", this could translate to "C:\repos\builds\Detours\Debug\x64" for the debug build and "C:\repos\builds\Detours\Release\x64" for the release build. In Visual Studio 2022, you would add the macro "$(SolutionDir)\builds\Detours$(Config)\x64" to the VC++ Directories in the list of directories to search. Visual Studio will expand it based on the configuration, ensuring that your console app's release version uses the release Detours DLL, and the debug version does the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants