2

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
AsadYarKhan
  • 678
  • 2
  • 14
  • 31
  • 4
    "Its not working" What does that mean? can you show us the error? – SingleNegationElimination Sep 08 '11 at 04:58
  • @TokenMacGuy This is the error I get, hello.exe the file not found and probably he might be facing the same ! – niko Sep 08 '11 at 07:04
  • You could possibly also be helped by this page: http://www.sandroid.org/TurboC/functionlist.html – Prof. Falken Sep 08 '11 at 11:35
  • 1
    @Amigable Clark Kant he wants the tcc command line options ! not the Turbo that uses gcc commands instead! – niko Sep 08 '11 at 11:39
  • Is the question about [Tiny C Compiler](https://en.wikipedia.org/wiki/Tiny_C_Compiler) (TCC) or about [Turbo C++](https://en.wikipedia.org/wiki/Turbo_C%2B%2B) (allegedly compiler executable name `TCC` or `tcc`)? – Peter Mortensen May 23 '23 at 21:40
  • How can the two be distinguished? By the folder name "`c:\tc\bin`"? [The tag](https://stackoverflow.com/questions/tagged/tcc) is for "TCC" / "Tiny C Compiler", but the tag wiki is empty. – Peter Mortensen May 23 '23 at 21:40
  • There is this: https://stackoverflow.com/a/55943295/2193968 If that isn't what you are after you could leave the -o test.exe out and then rename the executable once it is created. – Jerry Jeremiah May 23 '23 at 21:56
  • Note that the OP [has left the building](https://www.explainxkcd.com/wiki/index.php/979:_Wisdom_of_the_Ancients): *Last seen more than 7 years ago*. But it ought to be possible to untangle the intent, incl. [which compiler it is actually about](https://stackoverflow.com/questions/7343287/how-to-compile-a-program-of-the-c-language-manually-on-ms-dos-instead-of-borland/32967806#comment134581241_7343287). – Peter Mortensen May 23 '23 at 22:16

4 Answers4

3

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.

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
cyco130
  • 4,654
  • 25
  • 34
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

So, I think you should type:

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
  • What produced the output? `tcc` without any command-line parameters? – Peter Mortensen May 23 '23 at 21:17
  • Though [it isn't clear](https://stackoverflow.com/questions/7343287/how-to-compile-a-program-of-the-c-language-manually-on-ms-dos-instead-of-borland/32967806#comment134581241_7343287) if the question is about Tiny C Compiler (TCC) or about Turbo C++ (allegedly compiler executable name `TCC` or `tcc`). – Peter Mortensen May 23 '23 at 22:13
  • @PeterMortensen I think we can infer from "Borland" that it's not about Bellards TCC. Pretty hard core necromancing of a question about MSDOS programming, now one more decade obsolete! :-D Let's see if someone leaves a new answer ten years from now. – Prof. Falken May 24 '23 at 08:20
0

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);
}
barlop
  • 12,887
  • 8
  • 80
  • 109
0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
niko
  • 9,285
  • 27
  • 84
  • 131
  • 1
    Sorry, I was in a hurry. user672560 asked about Borlands Turbo C compiler for DOS from ca 1990, or so. You gave a link to Fabrice Bellards TCC. While the executable names unfortunately are the same, the compilers are very much not. – Prof. Falken Sep 08 '11 at 12:14
  • Thnx Niko Its Work Yahoooo ;) – AsadYarKhan Sep 10 '11 at 03:45
  • "`c:\tc\bin\ tcc`" doesn't seem right (with the space). – Peter Mortensen May 23 '23 at 21:12
  • Re *"I don't think we can give a name to the .exe file on the tcc command line prompt,"*: [It might be possible](https://stackoverflow.com/questions/7343287/how-to-compile-a-program-of-the-c-language-manually-on-ms-dos-instead-of-borland/7359784#7359784) with the "`-e`" command-line parameter: "`-exxx Executable file name`" – Peter Mortensen May 23 '23 at 21:23
  • 1
    The reference is to [Tiny C Compiler](https://en.wikipedia.org/wiki/Tiny_C_Compiler) (TCC). This has *** *** *** *** *** ***nothing*** *** *** *** *** *** to do with Turbo C++ (the name of the Turbo C++ compiler executable happens to be `TCC` or `tcc`). Unless the question is actually about Tiny C Compiler (the question is very vague and unclear). – Peter Mortensen May 23 '23 at 21:29