Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.lib error when I'm using a dll?

Tags:

c++

windows

dll

I'm trying to get some practice using windows DLLs (not used to them). I followed this article:

http://msdn.microsoft.com/en-us/library/ms235636(v=vs.80).aspx

To the letter.

And yet, I am receiving this error:

1>LINK : fatal error LNK1104: cannot open file '..\debug\math.lib'

My project is a dll project, not a lib. And there are no libs created from my projects at all (the whole solution).

Anybody have any idea what's wrong?

like image 842
Darkenor Avatar asked Mar 25 '11 01:03

Darkenor


People also ask

Can I use a DLL without lib?

The only way to access a bare DLL without a . lib file is to load the DLL explicitly with LoadLibrary() , get pointers to the exported functions you want to access with GetProcAddress() , and then cast those pointers to the proper function signature.

What is .LIB and .DLL file?

LIB is a static library where functions and procedures can be placed and called as the application is being compiled. A DLL or Dynamic Link Library does the same function but is dynamic in a sense that the application can call these libraries during run-time and not during the compilation.

What is a .LIB file?

A lib file is just a collection of related obj files, much like putting obj files in a directory. That is essentially what a lib file is, a library of obj files. For a static link, all of the obj files that an executable uses are combined into one file.

What is a .LIB file on Windows?

LIB (lib.exe) creates standard libraries, import libraries, and export files you can use with LINK when building a program. LIB runs from a command prompt. You can use LIB in the following modes: Building or modifying a COFF library. Extracting a member object to a file.


2 Answers

VS does not create an import library if dll does not actually export anything. To quickly check if that is your case, find your dll, open it with dependency walker and see if there are any exports at all.

If you find exports missing check if you did mark anything for export: either by declaring classes/functions as "__declspec( dllexport )" (when header is included in dll, dllimport when included by exe), or extern "C" plus module definition (.def) file.

like image 141
Eugene Avatar answered Sep 25 '22 08:09

Eugene


Your .dll project could be creating an import .lib. This simplifies using a DLL. An import .lib is a simple library that has the same functions as your dll, but it doesn't have the implementation -- when you use it, it loads the dll and then forwards the calls you make to the dll.

Or, the console project might think you have an import .lib -- but you don't.

The instructions for creating/using a dll you have are a little odd. I don't do it that way (with the Add References dialog). You might need to look through your project settings and see if you see any reference to math.lib -- or anything about creating an import .lib.

Also, check your output directories on the .dll project and see if math.lib (or any .lib) was created.

like image 36
Lou Franco Avatar answered Sep 22 '22 08:09

Lou Franco