D
D
Daniil Demidko2016-10-22 16:22:05
C++ / C#
Daniil Demidko, 2016-10-22 16:22:05

How to add a dynamic library to a project directly?

When using a dynamic library in a Visual C++ project, you need to add the *.lib file. How to do without it?
An example of how I do it with TDM-GCC:
A dynamic library is created - we get *.dll as an output.
A project is created using it, a relative path to the *.dll library is added in the linker settings, and the library itself is placed in the project folder so that the
linker can pick it up and take the addresses of the functions.
The *.dll library is relatively placed in the folder to the resulting executable, everything works.
An example of how I do it with VS:
A dynamic library is created - the output is a *.lib file and *.dll itself
A project is created using it, a relative path to the *.lib file of the library is added in the linker settings.
The *.dll library is placed in the folder to the resulting executable, everything works.
That's why you need *.lib ? How to do without it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2016-10-22
@Daniro_San

The task of lib is to specify, if not the code of functions, then at least how to link them from the DLL. In particular, how the function name is "mangled" when translating from C to C++. This very lib is the cost of sharing functions between the compiler and the linker.
I don’t know about MSVS/cl, but MinGW/ld from a certain moment started linking DLLs simply by the presence of this DLL, without building *.a (and Embarcadero/ilink32, as far as I know, was able to do this from the very beginning). On the one hand, it seriously simplifies life. On the other hand, for some tricky ways of converting names (or even without names, as in the notorious storm.dll), it will not catch out what to link with, *.a will still be required.
stackoverflow.com/questions/31708832/how-to-refere...
www.codeproject.com/Questions/613668/Is-it-possibl...
The simplest way that works on any compiler is to make a stub DLL with all the functions we need in the calling conventions we need and with the names we need to declare. The code can be anything, even empty. We compile, substitute this lib and the correct DLL.
The second way is to get a list of function names, collect them in *.def with the correct matches "name in code - name in DLL" and make *.lib out of this. What programs do this in MSVS - described by one of the links.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question