I am learning C Language and I have a question. If I compile 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?
2 Answers
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.

- 6,941
- 1
- 31
- 34
-
"Often" a library called `libc`? – Chris Lutz Aug 18 '11 at 06:30
-
In Linux it's often referred to as libc, the gnu version is called glibc. The name is also indicated by the url http://www.gnu.org/software/libc/libc.html – Mu Qiao Aug 18 '11 at 06:33
-
There is _always_ a standard library in a hosted environment, and it is always called `libc.whatever` because few linkers will link to a library that's not of the form `libNAME.whatever` (change `whatever` to the appropriate shared library ending for your platform). – Chris Lutz Aug 18 '11 at 06:47
-
Chris, you know better than that :-) The standard has nothing to say about library names and, while the vast majority of linkers act that way, not all _must._ In fact, the Borland ilink32 linker referenced in the question doesn't prefix the library names with `lib` and only appends `.lib` if there isn't already an extension. – paxdiablo Aug 18 '11 at 07:28