B
B
C++ / C#

Dynamic libraries under windows?

1. The names of the functions exported by the library can either be declared directly in the source code or placed in a file .lib. Which approach is better?

2. If you just declare a function in a library ( int a(){return 3;}) and then link ( g++ a.cpp -llibname) with an executable file, then everything will work, but why does the import of the LoadLibrary library work only with specially declared functions such ( __declspec(dllexport) __stdcall) why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Dubrovin, 2021-03-30
@z3apa3a

In Microsoft and compatible development environments, statically linked functions do not get into the dynamic library export table by default, so that they get into the export table (and can be called from outside), they must be declared as dllexport. Those. dllexport tells the linker that this symbol should be placed in the export table.
The first question is not very clear, .lib is needed so that the dynamic library can be connected to another project just like a static one, without manual imports and LoadLibrary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question