如何在MS-DOS而不是Borland上手动编译C语言程序

发布于 2024-12-03 15:07:55 字数 299 浏览 2 评论 0原文

我需要在 MS-DOS 中编译一个程序。我有Borland编辑器,我可以使用Alt + F9编译程序,但是它在后端做什么?我想在 MS-DOS 中编译它。我正在尝试这样做:

cd c:\tc\bin
tcc -o hello.exe hello.c

其中 hello.c 是我的文件,hello.exe 是我想要生成的文件。它不起作用。我应该怎么办?如何从 MS-DOS 手动编译 .cpp 文件?

I need to compile a program in MS-DOS. I have the Borland editor, and I can compile the program using Alt + F9, but what does it do at the backend? I want to compile it in MS-DOS. I’m trying this:

cd c:\tc\bin
tcc -o hello.exe hello.c

where hello.c is my file, and hello.exe the file I want to produce. It's not working. What should I do? And how do I compile a .cpp file manually from MS-DOS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

妳是的陽光 2024-12-10 15:07:55

如果我没记错的话,Borland/Turbo C 编译器的命令行选项看起来不像 gcc 选项。您应该尝试 tcc /? 获取命令行帮助。

If I remember correctly, Borland/Turbo C compiler's command line options didn't look like gcc options. You should try tcc /? for a command line help.

罪歌 2024-12-10 15:07:55
Turbo C++ Version 3.00 Copyright (c) 1992 Borland International
Syntax is: TCC [ options ] file[s]     * = default; -x- = turn switch x off
 -1      80186/286 Instructions    -2      80286 Protected Mode Inst.
 -Ax     Disable extensions        -B      Compile via assembly
 -C      Allow nested comments     -Dxxx   Define macro
 -Exxx   Alternate Assembler name  -G      Generate for speed
 -Ixxx   Include files directory   -K      Default char is unsigned
 -Lxxx   Libraries directory       -M      Generate link map
 -N      Check stack overflow      -O      Optimize jumps
 -P      Force C++ compile         -Qxxx   Memory usage control
 -S      Produce assembly output   -Txxx   Set assembler option
 -Uxxx   Undefine macro            -Vx     Virtual table control
 -X      Suppress autodep. output  -Yx     Overlay control
 -Z      Suppress register reloads -a      Generate word alignment
 -b    * Treat enums as integers   -c      Compile only
 -d      Merge duplicate strings   -exxx   Executable file name
 -fxx    Floating point options    -gN     Stop after N warnings
 -iN     Max. identifier length    -jN     Stop after N errors
 -k      Standard stack frame      -lx     Set linker option
 -mx     Set Memory Model          -nxxx   Output file directory
 -oxxx   Object file name          -p      Pascal calls
 -r    * Register variables        -u    * Underscores on externs
 -v      Source level debugging    -wxxx   Warning control
 -y      Produce line number info  -zxxx   Set segment names

因此,我认为您应该为 C 程序输入

tcc hello.c ,为 C++ 程序输入 tcc -P hello.cpp

Turbo C++ Version 3.00 Copyright (c) 1992 Borland International
Syntax is: TCC [ options ] file[s]     * = default; -x- = turn switch x off
 -1      80186/286 Instructions    -2      80286 Protected Mode Inst.
 -Ax     Disable extensions        -B      Compile via assembly
 -C      Allow nested comments     -Dxxx   Define macro
 -Exxx   Alternate Assembler name  -G      Generate for speed
 -Ixxx   Include files directory   -K      Default char is unsigned
 -Lxxx   Libraries directory       -M      Generate link map
 -N      Check stack overflow      -O      Optimize jumps
 -P      Force C++ compile         -Qxxx   Memory usage control
 -S      Produce assembly output   -Txxx   Set assembler option
 -Uxxx   Undefine macro            -Vx     Virtual table control
 -X      Suppress autodep. output  -Yx     Overlay control
 -Z      Suppress register reloads -a      Generate word alignment
 -b    * Treat enums as integers   -c      Compile only
 -d      Merge duplicate strings   -exxx   Executable file name
 -fxx    Floating point options    -gN     Stop after N warnings
 -iN     Max. identifier length    -jN     Stop after N errors
 -k      Standard stack frame      -lx     Set linker option
 -mx     Set Memory Model          -nxxx   Output file directory
 -oxxx   Object file name          -p      Pascal calls
 -r    * Register variables        -u    * Underscores on externs
 -v      Source level debugging    -wxxx   Warning control
 -y      Produce line number info  -zxxx   Set segment names

So, I think you should type:

tcc hello.c for C programs and tcc -P hello.cpp for C++ programs.

夕色琉璃 2024-12-10 15:07:55

我相信这些事情一定有效:

c:\tc\bin\tcc -c File.c     \\ To generate the object file
c:\tc\bin\tcc -o File.obj   \\ To generate the EXE file from the object file. And please use .obj, not .o
c:\tc\bin\ tcc -run File.c  \\ To generate the EXE file without the .obj file
c:\tc\bin\File.exe          \\ To run the EXE file

我不知道为什么

tcc -o good.exe File.obj \\ Not working. The error is 'good.exe' file not found

我认为我们不能在 tcc 命令行提示符上为 .exe 文件命名,但这在海湾合作委员会是可能的。我对TCC不太了解。如果我找到了,我会让你知道的!

只需看看这些Tiny C 编译器参考文档 。这是我在谷歌上找到的。谷歌搜索会让你变得更强大,所以当你不知道的时候,继续谷歌搜索。

I believe these things must work:

c:\tc\bin\tcc -c File.c     \\ To generate the object file
c:\tc\bin\tcc -o File.obj   \\ To generate the EXE file from the object file. And please use .obj, not .o
c:\tc\bin\ tcc -run File.c  \\ To generate the EXE file without the .obj file
c:\tc\bin\File.exe          \\ To run the EXE file

I don’t know why the

tcc -o good.exe File.obj \\ Not working. The error is 'good.exe' file not found

I don't think we can give a name to the .exe file on the tcc command line prompt, but it's possible in GCC. I don’t know about TCC much. If I find it, I will let you know it!

Just take a look at these Tiny C Compiler Reference Documentation. This is what I found on Google. And googling makes you more powerful, so keep on googling the things when you don’t know.

心碎的声音 2024-12-10 15:07:55

根据 Falken 教授的回答

tcc file.c <-- will compile in C

tcc file.cpp <-- will compile in cpp

tcc file.ext where .ext是除 cpp 以外的任何内容,将在 C 中编译除非使用 --P,否则使用 cpp 来编译它,在这种情况下使用 .cpp,即使扩展名是 .c

我在 VM 中运行 TCC 并且不能从那里复制/粘贴到这里。但是你的测试应该找到与我相同的结果,如果不是,那么也许我犯了错误,但是你可以自己测试一下这个在 C 中工作而不是 CPP 中工作的代码,以及在 CPP 中工作而不是 C 中工作的代码。然后你可以进行实验更改扩展名,以及是否使用 -P。

以下代码仅适用于 C

conly.c

(一位 C++ 专家告诉我以下示例,适用于 C 而不是 C++,因为 C 允许 void* -> T* 转换。C++ 不支持)

#include <stdio.h>
#include <stdlib.h>
void main() {int *x=malloc(4);}

以下代码仅适用于 C++

cpponly.cpp

#include <stdio.h>
void main() {
 int a=9;
 int& b=a;
 printf("b=%d",b);
}

Further to Prof Falken's answer

tcc file.c <-- will compile in C

tcc file.cpp <-- will compile in cpp

tcc file.ext where .ext is anything other than cpp, will compile in C Unless --P is used then cpp is used to compile it, in which case .cpp is used, even if the extension is .c

I am running TCC in a VM and can't copy/paste from there here. But your test should find the same result as mine, if not, then perhaps I erred, but you can test for yourself given this code that works in C and not CPP, and code that works in CPP and not C. You can then experiment with changing the extension, and using -P or not.

The following code works in C only

conly.c

(A C++ expert told me re the following example, works in C and not C++, because C allows void* -> T* conversions. C++ does not)

#include <stdio.h>
#include <stdlib.h>
void main() {int *x=malloc(4);}

The following code works in C++ only

cpponly.cpp

#include <stdio.h>
void main() {
 int a=9;
 int& b=a;
 printf("b=%d",b);
}
北方的韩爷 2024-12-10 15:07:55
  • 加载 bc.exe 文件 bc.exe 是 Borland IDE
  • 确保您的 .c 文件包含在项目中
  • 以创建“新”项目,选择“新建”,然后“添加”您的 .c 文件,然后
    节省。
  • 加载项目,您的 .c 文件应该出现在
  • 顶部的编辑器中,转到“选项”、“链接器”,您应该看到一个复选框
    创建 .exe 文件的输出。选中那个框。
  • 关闭它并返回主菜单,其中显示“运行”。
  • 选择运行,这将运行该程序并为您创建 .exe 文件。
  • load the bc.exe file bc.exe is the Borland IDE
  • make sure you have your .c file included in a project
  • to create a "new" project, select new, and "add" your .c file and
    save.
  • load the project and your .c file should appear in the editor
  • at the top, go to "options", "linker", and you should see a checkbox
    to create output to .exe file. Check that box.
  • close that and go back to main menu where it says "Run".
  • select run, and that will run the program and create the .exe file for you.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文