I'm building an open source C++ library called ITPP in Visual Studio 2010. It builds successfully and so I try to 开发者_JS百科build the test program that comes with it in order to try it. I get linking errors in the test program saying that the first library I built has some linking errors in that it can't find some functions.
I think I know what library is missing, but it's like VS doesn't care.
What are the possible reasons that when I build the library straight up it links correctly but when I try to use it somewhere the IDE says that the lib I built has linking errors?
Thanks,
mj
Has the test app setup the dependency on the lib correctly? Have you added the directory your new lib is in to Visual Studios search path? (Tools->Options->Projects and Solutions->VC++ Directories). Does the test app list the lib under the linker "additional dependencies" option (check project properties->linker->input->Additional Dependencies). Or alternatively, if the test app is in the same solution, under "Project dependencies" in the test app, is the lib project listed under dependencies.
Is the .lib an import lib to a dll? An import lib is simply a front-end to a dll. It causes your dll/exe to automatically load the dll at startup, and take the dll down on exit. It also provides a static front end to all the symbols in the dll. Problems that can happen include if a symbol in the dll wasn't exported, and therefore wasn't placed in the import lib, causing linker errors.
In visual studio, is an older version of the .lib sitting in the same path as your test exe. This will happen to me sometimes when the I've got the .lib in my project and I've set it to copy to some location where all my common libraries exist across multiple projects. Sometimes I'll build the .libs project in the same solution in the test app. Other times I'll build it outside the test app. When you build it in the solution, the lib gets copied to the same directory as your test executable. This comes first in the lib search path during linking.
Is there an older copy of the lib somewhere else on the linker's search path? Same things can happen here as in 3 above.
If all else fails turn on verbose linking as indicated here. See where visual studio is importing the lib from, see if it matches your expectations.
A static library will be produced even if some symbols (functions/variables) referenced in it are not available. When you try to build a DLL or an EXE, then all referenced symbols must be available - so the errors you get indicate that these symbols are indeed missing, and that neither your library nor any other library/source provided it.
精彩评论