问题
I'm finding it really difficult to properly link a .lib file to my C++ Win32 Console Application. Here's my problem.
Just as in this MSDN article, I have developed a MathFuncsLib.lib file.
http://msdn.microsoft.com/en-us/library/ms235627%28v=vs.80%29.aspx
Then, in the MyExecRefsLib Win32 Console App, I want to link to the above file. So, inside MyExecRefsLib folder (same folder where .sln file resides) I created a directory called "LibraryFiles" and placed both MathFuncsLib.lib file AND MathFuncsLib.h file.
Then, in Properties->Linker->Input I added both "MathFuncsLib.lib" and "MathFuncsLib.h" (without full path) and then in Properties->Linker->Additional Library Directories I added the path to my folder "LibraryFiles" which is what pretty much EVERY thread on the web about this problem tells me to do.
But now it gives me the following error:
fatal error C1083: Cannot open the include file. 'MathFuncsLib.h': No such file or directory.
What am I doing wrong? Please help. Note that my code is exactly the same as what's in the above given MSDN link.
回答1:
To link with a .lib file, you just need to:
- right clic on the project name, select Properties
- under Properties->configuration properties->C/C++->General item "other include directories" add the path to your .h file
- under Properties->Linker->Input add the path and name of your .lib file
And that's it.
来源:https://stackoverflow.com/questions/6093325/how-to-link-a-lib-in-visual-studio-2008-c