Compiled languages basics

c++dll

please, could someone explain to me a few basic things about working with languages like C? Especially on Windows?

  1. If I want to use some other library, what do I need from the library? Header files .h and ..?

  2. What is the difference between .dll and .dll.a.? .dll and .lib? .dll and .exe? What is .def?

  3. Does it matter how was the library compiled? I mean, is it possible to use, on Windows, a C++ library compiled by VC from within my C code compiled by MinGW?

  4. To use another library, what is preferred way? LoadLibrary() or #include <>?

  5. There are some libraries which only provide the source code or .dll – how to use such libraries? Do I have to recompile them every time I rebuild my project?

  6. How do I create one big .exe? Is this called "static linking"?

  7. How to include some random file into .exe? Say a program icon or start-up song?

  8. How do I split my huge .c into smaller ones? Do I need to create for every part a header file which then I include in the part with WinMain() or main()?

  9. If there is a library which needs another library, is it possible to combine these two into one file? Say, python26.dll needs msvcr90.dll and Microsoft.VC90.CRT.manifest

  10. What happens if I don't free previously allocated memory? Is this going to be cleaned up if the program (process) dies?

Well, so many question… Thanks for every info!

Best Solution

1: If I want to use some other library, what do I need from the library? Header files .h and ..?

... and, usually a *.lib file which you pass as an argument to your linker.

2: What is the difference between .dll and .dll.a.? .dll and .lib? .dll and .exe? What is .def?

This might be useful: Static libraries, dynamic libraries, DLLs, entry points, headers … how to get out of this alive?

3: Does it matter how was the library compiled? I mean, is it possible to use, on Windows, a C++ library compiled by VC from within my C code compiled by MinGW?

Yes, it matters. For interop between compilers, the normal way is to use a C-style (not C++-style) API, with well-defined parameter-passing conventions (e.g. __stdcall), or to use 'COM' interfaces.

4: To use another library, what is preferred way? LoadLibrary() or #include <>?

#include is for the compiler (e.g. so that it can compile calls to the library); and LoadLibrary (or, using a *.lib file) is for the run-time linker/loader (so that it can substitute the actual address of those library methods into your code): i.e. you need both.

5: There are some libraries which only provide the source code or .dll - how to use such libraries? Do I have to recompile them every time I rebuild my project?

If it's only source then you can compile that source (once) into a library, and then (when you build your project) link to that library (without recompiling the library).

6: How do I create one big .exe? Is this called "static linking"?

Yes, compile everything and pass it all to the linker.

7: How to include some random file into .exe? Say a program icon or start-up song?

Define that in a Windows-specific 'resource file', which is compiled by the 'resource compiler'.

8: How do I split my huge .c into smaller ones? Do I need to create for every part a header file which then I include in the part with WinMain() or main()?

Yes.

9: If there is a library which needs another library, is it possible to combine these two into one file? Say, python26.dll needs msvcr90.dll and Microsoft.VC90.CRT.manifest

I don't understand your question/example.

10: What happens if I don't free previously allocated memory? Is this going to be cleaned up if the program (process) dies?

Yes.