问题
I need to compile a program in MS DOS. I have Borland Editor, I can compile it using Alt+F9 but the things is what it do at the backend. I want to compile it in MS DOS. I m trying this:
c:\tc\bin>tcc -o hello.exe hello.c
where hello.c
is is my file, hello.exe
the file I want to produce. Its not working, what shouldI do? and also please tell me also how do I compile .cpp
file manually from MS DOS.
回答1:
I belive this things must work
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
I dont know why the
tcc -o good.exe File.obj \\not working, the error is good.exe file not found
I think we cant give a name to .exe file in tcc command line prompt.but its possible in gcc. I dont know about TCC much. If i find it i will let you know it !
Just take a look at these http://bellard.org/tcc/tcc-doc.html#SEC3. This is what I found on google . and googling makes you more powerful so keep on googling the things when you dont know .
Thanks
回答2:
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.
回答3:
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>
So, I think you should type:
tcc hello.c
for C programs and tcc -P hello.cpp
for C++ programs.
回答4:
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);
}
来源:https://stackoverflow.com/questions/7343287/how-to-compile-a-program-of-c-language-manually-on-ms-dos-instead-of-borland