2011-09-08 50 views
2

我需要在MS DOS中编译程序。我有Borland编辑器,我可以使用Alt + F9进行编译,但事情就是它在后端执行的操作。我想在MS DOS中编译它。我米试图这样的:如何在MS DOS而不是Borland上手动编译c语言程序

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

其中hello.c是我的文件,hello.exe我想生产的文件。它不工作,我该怎么办?也请告诉我如何从MS DOS手动编译.cpp文件。

+4

“它不工作” 是什么意思呢?你能告诉我们错误吗? – SingleNegationElimination

+0

@TokenMacGuy这是我得到的错误,hello.exe文件未找到,可能他会面临相同的问题! – niko

+0

您也可以通过以下页面获得帮助:http://www.sandroid.org/TurboC/functionlist.html –

回答

0

我相信这个事情必须努力

c:\tc\bin\tcc -c File.c \\ To generate objective file 
c:\tc\bin\tcc -o File.obj \\ To generate exe from obj and please use .obj and not .o 
c:\tc\bin\ tcc -run File.c \\ to generate exe file without .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 

我认为,我们不能提供一个名称.EXE在TCC命令行文件prompt.but其可能在GCC。我不太了解TCC。如果我找到它,我会让你知道它!

只要看看这些http://bellard.org/tcc/tcc-doc.html#SEC3。这是我在谷歌上找到的。和谷歌搜索使你更强大,所以当你不知道的时候继续使用谷歌搜索的东西。

感谢

+2

TC和TCC不一样。 –

+1

对不起,我很匆忙。 user672560询问了从1990年左右开始用于DOS的Borlands Turbo C编译器,等等。你给了Fabrice Bellards TCC的链接。虽然可执行程序的名称不幸是相同的,但编译器却不是。 –

+0

Thnx Niko Its Work雅虎;) – AsadYarKhan

3

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

2
 
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:\TC\BIN> 

所以,我认为你应该输入:

tcc hello.c的C程序和tcc -P hello.cpp的C++程序。

0

继飞劲教授的回答

tcc file.c < - 将编译用C

tcc file.cpp < - 将在CPP编译

TCC file.ext其中.EXT比CPP其他任何东西,将在C编译除非使用-P,那么使用cpp编译它,在这种情况下使用.cpp,即使扩展名是.c

我正在运行TCC一个虚拟机,不能从这里复制/粘贴。但是你的测试应该找到和我一样的结果,如果没有,那么也许我犯了错误,但是你可以测试你自己给出的代码是否适用于C而不是CPP,代码适用于CPP而不是C。然后你可以实验改变扩展名,并使用-P或不。

下面的代码工作中仅C

conly.c

(A C++专家告诉我再下面的例子中,工作在C和不是C++,因为C允许无效* - > 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); 
}