Tom
Tom

Reputation: 393

visual c++, LINK : fatal error LNK1104: cannot open file

I'm new C++, I have a dll file called DiceInvaders.dll, in my project, I need to use this library, I'm using visual c++ 2010, I set the Linker Input as DiceInvaders.lib and DiceInvaders.dll, I also copied this dll file to my porject directory, I always got error in this line of code:

m_lib = LoadLibrary("DiceInvaders.dll");
assert(m_lib);

The error is assertion failure. How should I solve this? Thank you in advance.

Upvotes: 1

Views: 10357

Answers (1)

Captain Obvlious
Captain Obvlious

Reputation: 20063

First you cannot pass the DLL to the linker like you are, it is not a file type that the linker recognizes and cannot be linked that way. When you create the Diceinvaters.dll file the linker will create an import library with the same filename and the extension .lib. It appears this is already being done. That is the library file you should pass to the linker when building any application that uses it.

Second, the Diceinvaders.dll file must be accessible in the DLL search path. This varies slightly depending on which version of Windows you are using but is generally something like the following

  1. The directory the program was loaded from.
  2. The current working directory.
  3. The System directory.
  4. The Windows directory.
  5. The directories that are listed in the PATH environment variable.

Placing the DLL in your project directory is not going to be enough. Instead you should place it in the same directory as the EXE file(s) that have a dependency on it.

Upvotes: 7

Related Questions