了解 C 运行时
我正在学习C语言,我有一个问题。 如果我在一台 Windows PC 上用 BorlandC 编译并制作 C 程序的可执行文件,然后将此文件传输到另一台没有编译器的 Windows PC,它如何在没有 C 运行时的情况下运行以及内存管理如何工作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果使用静态链接,则可以以相对轻松的方式完成此操作。这意味着当您编译/链接(在您的计算机上)时,运行时库将绑定到可执行文件中,而不是在运行时动态加载(在另一台计算机上)。
如果您使用动态链接,那么这些库必须在运行代码的运行时可用,以便加载程序(操作系统的一部分)可以找到它们并将它们链接到其中。
对于静态/动态的一个很好的解释有关链接差异,请参阅此处。
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.
对于 C 语言,通常有一个名为“libc”的共享库,它应该随您的操作系统一起提供。内存管理是由你自己的程序用malloc(calloc等)和free来处理的。它们也是图书馆的一部分。
另请注意,编译器和运行时是不同的东西(您可以在没有编译器的情况下安装运行时二进制文件),尽管有时它们捆绑在一起。
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.