AsadYarKhan
AsadYarKhan

Reputation: 688

How to compile a program of the C language manually on MS-DOS instead of Borland

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?

Upvotes: 3

Views: 14078

Answers (5)

x y
x y

Reputation: 1

  • 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.

Upvotes: 0

niko
niko

Reputation: 9393

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.

Upvotes: 0

Prof. Falken
Prof. Falken

Reputation: 24867

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.

Upvotes: 2

barlop
barlop

Reputation: 13743

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);
}

Upvotes: 0

cyco130
cyco130

Reputation: 4934

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.

Upvotes: 3

Related Questions