开发者

Understanding C runtimes

开发者 https://www.devze.com 2023-03-29 11:42 出处:网络
I am learning C Language and I have a question. If I compil开发者_高级运维e and make an executable for C program in say BorlandC on one Windows PC and then transfer this file to another Windows PC whi

I am learning C Language and I have a question. If I compil开发者_高级运维e and make an executable for C program in say BorlandC on one Windows PC and then transfer this file to another Windows PC which does not have the compiler, how does it run where there is no C runtime and how does the memory management work?


You can do this in a relatively painless way if you use static linking. That means the run time libraries are bound into your executable when you compile/link (on your machine), rather than being loaded up dynamically at run time (on the other machine).

If you use dynamic linking, then the libraries have to be available at run time where you're running the code, so the loader (part of the OS) can find them and link them in.

For a good explanation of the static/dynamic linking differences, see here.


For C language, there is often a shared library called "libc" that should be shipped with your OS. Memory management is handled by your own program with malloc(calloc, etc.) and free. They are also part of the library.

Also notice that the compiler and runtime are different things (you can install the runtime binary without the compiler), although sometimes they are bundled together.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号