0
votes

When trying to import an external library from a different drive I keep getting error LNK1104 "cannot open foo.lib"

I set up the correct paths in:

Properties -> Configuration Properties -> VC++ Directories -> Include Directories

Properties -> Configuration Properties -> VC++ Directories -> Library Directories

Properties -> Configuration Properties -> C/C++ -> General -> Additional Include Directories

Properties -> Configuration Properties -> Linker -> General -> Additional Library Directories

And the correct .lib filename including extension in:

Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies

This still gives me the error and the only way I have found to fix it is to manually copy the .lib (or .dll) file inside my project, by copying it the linker can find it and link it correctly.

Pretty much all the questions I have found on SO say to set the correct paths and filename of the .lib like I did, why this is not working and I have to directly copy the .lib file inside my project directory to have it work?

1
I set up the correct paths in Your compiler is telling you that you have not set the correct paths. Is there a space in the path?drescherjm
@drescherjm there is no space and I have checked like 10 times trying with both relative and absolute paths, manually writing the path and using VS folder explorerJohn Doe
Maybe one of the other paths before the entry you added in Additional Include Directories is not correct.drescherjm
I assume you are not mixing 32 and 64 bit and that the .lib you are using is the same file you copied so its definitely not corrupt.drescherjm
@drescherjm I checked all the paths again but they are correct, I'm not mixing 32 and 64 bit (I'm using only 64) and the lib I copied is the one in the folder which path I wrote in the properties. Also this is a static library, I don't know if that helps or not since I need to do the same for dynamic libraries too.John Doe

1 Answers

0
votes

According to the Error LNK1104, as far as I'm concerned the cause of this issue is that the compiler couldn't search the directory of the .lib file.

To fix a path issue, we should verify that the LIB environment variable is set and contains all the directories for the libraries you use, for every configuration you build. In the IDE, the LIB variable is set by the Library Directories property on the VC++ Directories Property Page.

If the static library is not part of the solution,In the VC++ Directories property page, I suggest you should try to add the path to the directory where the .lib file is located in Library Paths.

For more details ,I suggest you could refer to the link.