开发者

Visual Studio DLL project with DLL dependencies, unresolved external symbols

开发者 https://www.devze.com 2023-01-14 16:45 出处:网络
I\'m new to Windows concepts.I\'m trying to develop a DLL that also dynamically links against other DLL\'s.I\'m using Visual Studio 2010.At linking time Visual studio tells me it\'s trying to link aga

I'm new to Windows concepts. I'm trying to develop a DLL that also dynamically links against other DLL's. I'm using Visual Studio 2010. At linking time Visual studio tells me it's trying to link against a bunch of .lib files. I don't think Visual Studio should attempt to re开发者_C百科ad any .LIB files if I want my code to perform dynamic linking is that correct? Or do I not understand the use of .LIB files enough?

thank you


How I understand, you are a little confused, because you want to use DLLs instead of LIBs.

The trick is that Kernel32.Lib, User32.Lib, AdvAPI32.Lib and so on has no implementation of the function which you use. Moreover if you use functions like CreateFileW or MessageBoxW in your program the references to the function will be unresolved after the compilation. So without having LIBs the unresolved references will stay also in the EXE. That will be bad of cause. To be executable the EXE must have resolved all external references and moreover know exactly which functions should be found in which DLLs. So named import library help to solve the problem. The import library Kernel32.Lib for example has information about CreateFileW function and User32.Lib has information about MessageBoxW. If you use a list of import libraries like Kernel32.Lib, User32.Lib, AdvAPI32.Lib your EXE resolves all referenced and includes the exact list of DLLs which it need and the list of functions used in the corresponding DLL in a special Import table (see http://en.wikipedia.org/wiki/Portable_Executable#Import_Table, http://msdn.microsoft.com/en-us/library/ms809762.aspx and http://www.microsoft.com/whdc/system/platform/firmware/pecoff.mspx). So If one starts your EXE the operation system loads the DLL in the address space of the process and resolves till the end all references up to the addresses of all functions used.

Typically import libraries will be created by linker (link.exe) when one compile a DLL. It is also possible to create an import library which corresponds to the DLL with respect of lib.exe utility. (see http://msdn.microsoft.com/en-us/library/0b9xe492.aspx)


As I recall, Visual Studio's compiler resolves .DLL files by linking against stub .LIB files.

Check, one of them should be kernel32.lib.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号