使用Turbo C编译并链接到.com文件 [英] Compile and Link to .com file with Turbo C

查看:87
本文介绍了使用Turbo C编译并链接到.com文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Turbo C编译器和链接器将一个简单程序编译并链接到DOS .com文件.通过这种方式,我尝试了我能想到的最简单的C程序.

I'm trying to compile and link a simple program to a DOS .com file using Turbo C compiler and linker. By that I try the simplest C-program I can think of.

void main()
{}

是否有命令行参数可链接到Turbo C链接器中的com文件?

Are there command line arguments to link to com files in the Turbo C Linker?

我从链接器收到的错误消息如下:

The Error Message I get from the Linker is the following:

致命:无法生成COM文件:无效的入口点地址"

"Fatal: Cannot generate COM file: invalid entry point address"

我知道com文件需要在100h处进入.Turbo C是否可以选择设置此地址?

I know that com files need entry point to be at 100h. Does Turbo C have an option to set this address?

推荐答案

自从我真正尝试使用Turbo-C进行此类操作以来已经有很长时间了.如果您要分别在命令行上使用TCC.EXE和TLINK.EXE进行编译和链接,那么这可能对您有用.

It has been a long time since I have genuinely tried to use Turbo-C for this kind of thing. If you are compiling and linking on the command line separately with TCC.EXE and TLINK.EXE then this may work for you.

要编译并链接到COM文件,可以对每个C源文件执行此操作,为每个C源文件创建OBJ文件:

To compile and link to a COM file you can do this for each one of your C source files creating an OBJ file for each:

tcc -IF:\TURBOC3\INCLUDE -c -mt file1.c
tcc -IF:\TURBOC3\INCLUDE -c -mt file2.c
tcc -IF:\TURBOC3\INCLUDE -c -mt file3.c

tlink -t -LF:\TURBOC3\LIB c0t.obj file1.obj file2.obj file3.obj,myprog.com,myprog.map,cs.lib

每个 C 文件使用 -mt (微型内存模型)分别编译为相应的OBJ文件. -I 选项指定环境中INCLUDE目录的路径(相应更改). -c 选项告诉TCC仅编译为OBJ文件.

Each C file is compiled individually using -mt (tiny memory model) to a corresponding OBJ file. The -I option specifies the path of the INCLUDE directory in your environment (change accordingly). The -c option tell TCC to compile to a OBJ file only.

链接 -t 告诉链接器生成COM程序(而不是EXE)时, -LF:\ TURBOC3 \ LIB 是库目录的路径在您的环境中(进行相应更改).C0T.OBJ是微型内存模型的 C 运行时文件.这包括您缺少的主要入口点.然后,您列出所有其他OBJ文件,并用空格分隔.第一个逗号之后是输出文件名.如果使用 -t 选项,请使用COM扩展名命名程序.第二个逗号后是MAP文件名(如果您不需要MAP文件,则可以将文件名留空).第三个逗号之后是用空格分隔的库列表.对于小型模型,您想使用小型模型库.用于小型内存模型的 C 库称为CS.LIB.

When linking -t tells the linker to generate a COM program (and not an EXE), -LF:\TURBOC3\LIB is the path to the library directory in your environment (change accordingly). C0T.OBJ is the C runtime file for the tiny memory model. This includes the main entry point that you are missing. You then list all the other OBJ files separated by a space. After the first comma is the output file name. If using -t option name the program with a COM extension. After the second comma is the MAP file name (you can leave the file name blank if you don't want a MAP file). After the third comma is the list of libraries separated by spaces. With the tiny model you want to use the small model libraries. The C library for the small memory model is called CS.LIB .

例如,如果我们有一个名为TEST.C的源文件,看起来像:

As an example if we have a single source file called TEST.C that looks like:

#include<stdio.h>

int main()
{
    printf("Hello, world!\n");
    return 0;
}

如果我们要编译并链接此命令,则将是:

If we want to compile and link this the commands would be:

tcc -IF:\TURBOC3\INCLUDE -c -mt test.c
tlink -t -LF:\TURBOC3\LIB c0t.obj test.obj,test.com,test.map,cs.lib

您将必须在自己的环境中使用路径.这些命令应生成一个名为TEST.COM的程序.运行时应打印:

You will have to use the paths for your own environment. These commands should produce a program called TEST.COM. When run it should print:

你好,世界!

这篇关于使用Turbo C编译并链接到.com文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆