ideasrule
ideasrule

Reputation: 210

Linking DLL with Visual C++

I'm trying to use an external DLL (provided by AutoItX) with Visual C++ 2010. AutoItX provides a DLL, but for some reason not a LIB, so I generated one with Visual Studio.

The problem is that the linker seems to have trouble linking against the library. I added AutoItX3.lib as an additional dependency under Properties->Linker -> Inputs, and added the directory to Properties -> Linker -> General -> Additional Library Directories. No matter what I do, I still get these errors:

1>main.obj : error LNK2019: unresolved external symbol _AU3_Send@8 referenced in function _WinMain@16
1>main.obj : error LNK2019: unresolved external symbol _AU3_WinWaitActive@12 referenced in function _WinMain@16
1>main.obj : error LNK2019: unresolved external symbol _AU3_Run@12 referenced in function _WinMain@16
1>main.obj : error LNK2019: unresolved external symbol _AU3_Sleep@4 referenced in function _WinMain@16

AU3_Send, AU3_WinWaitActive, AU3_Run, and AU3_Sleep are functions called by the program, main.cpp. I'm really out of ideas, because these functions clearly exist in the DLL. Any help would be appreciated.

Upvotes: 1

Views: 1853

Answers (1)

mox
mox

Reputation: 6324

It is very common to provide only DLLs as a mean of interfaces. Many software providers do that. Doing this has following impacts (consequences):

  • the client applications can only dynamically link to the library provided (hence the name Dynamic-Link Library). The binding between the provider (the library) and the consumer (the App or any other Library) is made dynamically.
  • the client must use LoadLibray and GetProcAddress in order to bind the library and retrieve the Symbols (functions) desired
  • the interface (contract) between the Library and the consumer should be documented via a Header file - see AutoIt3.h for example - (or any other documentation like a help file, ..)
  • No LIB is provided (since it is not needed), since the Linking takes place at runtime, not at compiler/linker time

To resolve your problem you just need to remove the static dependency (the LIB) you put in the Visual Studio configuration and set the dependency at runtime using LoadLibrary and GetProcAddress

Upvotes: 1

Related Questions