Compiled language basics

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

  • If I want to use some other library, what do I need in the library? .H and ..?

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

  • Doesn't matter how the library was compiled? I mean, can I use on Windows a VC compiled C ++ library from my MinGW compiled C code?

  • To use a different library, what is the preferred way? LoadLibrary () or #include <>?

  • There are several libraries that only provide source code or .dlls - how to use such libraries? Do I have to recompile them every time I rebuild my project?

  • How do I create one large .exe file? Is this called "static linking"?

  • How do I include some random file in the .exe? Say a program icon or a starting song?

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

  • If there is a library that needs another library, is it possible to combine the two into one file? Let's say python26.dll needs msvcr90.dll and Microsoft.VC90.CRT.manifest

  • What happens if I don't free the previously allocated memory? Will this be cleaned up if the program (process) dies?

Well, so many questions ... Thanks for every info!

+2


source to share


3 answers


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

... and usually the file *.lib

that 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 live?

3: Doesn't matter how the library was compiled? I mean, can I use on Windows a C ++ library compiled by VC from my C code compiled by MinGW?

Yes, it is important. For interoperability between compilers, the usual way is to use a C-style API (not C ++), with well-defined parameter passing conventions (for example __stdcall

), or to use COM interfaces.

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

#include

intended for the compiler (for example, so that it can compile calls to a library); and LoadLibrary

(or, using a file *.lib

) - for the linker / loader at runtime (so that it can replace the actual address of these library methods with your code): i.e. you need both.

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

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



6: How to create one big .exe file? Is this called "static linking"?

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

7: How to include some random file in .exe? Say a program icon or a starting song?

Define this in the Windows resource file that is compiled by the resource compiler.

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

Yes.

9: If there is a library that needs another library, is it possible to combine the two into one file? Let's 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 the previously allocated memory? Will it be cleaned up if the program (process) dies?

Yes.

+3


source


If I want to use some other library, what do I need from the library? .H and ..?

You need a .h or .hpp header for C, C ++, although some languages ​​don't require header files. You will also need .a, .so, .dll, .lib, .jar, etc. files. These files contain machine code that you can link in your program. Not to mention that the library format should be understood by you by the linker.

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

dll and .a are library files that contain code components that you can link in your own program..exe is your final program that already had .a or .dll linked.

Doesn't matter how the library was compiled? I mean, can I use on Windows a C ++ library compiled by VC from my C code compiled by MinGW?

Yes, it is important that the library you are using is compatible with your platform. Generally, Unix libraries don't run on Windows and vice versa if you are using JAVA you are better off working as .jar files usually work on any platform with JAVA enabled (although version matters)

To use a different library, what is the preferred way? LoadLibrary () or #include <>?

include is not a way to use a library, just a preprocessor directive telling you that the preprocessor includes the external source file in your current source file. This file can be any file other than .h, although it will usually be .h or .hpp You would be better off not deciding when to load the library into the runtime or your linker unless you know for sure what loading the library into a certain point in time will add some value to your code. The execution cost and the exact way to do it depends on the platform.

There are several libraries that only provide source code or .dlls - how to use such libraries? Do I have to recompile them every time I rebuild the project?

If you have the source code, you need to recompile it every time you make changes to it. however, unless you changed the source of the library, there is no need to recompile it anyway. A building tool like Make is smart enough to make this decision for you.



How do I create one large .exe file? Is this called "static linking"?

The creation of a static .exe depends on the build tool used. with gcc this usually means you have a static option for you - gcc -static -o my.exe my.c

How do I include some random file in the .exe? Say a program icon or a starting song?

Nothing in programming is random. If it were, we would have problems. Again, how you can play a song or display an icon depends on the platform you are using on some platforms, it may not be possible.

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

You will need a header file with all of your function prototypes, and you can split your program into multiple .c files that contain one or more functions. The main files will include a header file. All source files must be compiled individually and then linked into a single executable file. Typically, you will get an .o for each .c and then you link all the .o together to get an .exe

If there is a library that needs another library, is it possible to combine the two into one file? Let's say python26.dll needs msvcr90.dll and Microsoft.VC90.CRT.manifest

Yes, one library may need a different library, however it is not recommended to put different libraries together, perhaps you are violating IPR, and because each library is usually a well-defined unit with a specific purpose and combines them into one does not make much sense.

What happens if I don't free the previously allocated memory? Will it be cleaned up if the program (process) dies?

Again it depends on the platform, usually on most OS memory is recovered after the program dies, but on some platforms, such as an embedded system, it can be lost forever. It's always a good idea to clean up the resources your program was using.

+1


source


In all seriousness, the place to learn how to start your local environment is the documentation for your local environment. After all, we don't even know exactly what your environment is, much less what it is in front of us.

But here are some answers:

1.

You need headers and some kind of binding object. Or you need a source so you can create them.

3.

It is important that the library is in a format your linker understands. In C ++ languages, and possibly other languages, it is also necessary to understand the name used.

6.

Forcing all library code to be included in the executable is really called "static linking".

7.

There fooobar.com/questions/230482 / ... .

0


source







All Articles