hi there ,
i want to call the c compiler (using mingw) that can compile and run my c progarm through the .bat file
can anyone can help ...
can enyone give me a small example
hi there ,
i want to call the c compiler (using mingw) that can compile and run my c progarm through the .bat file
can anyone can help ...
can enyone give me a small example
in your .bat file you should just need 2 commands: first run the command to compile the program, then on the next line type the name of the file. (both assuming current directory, otherwise specify complete path, of course).
thats the easy part. what you need to know is the command to compile your source code, which i imagine would be on the compiler's website or in its documentation.
Is there any particular reason that you want to do this?
Anyway, assuming MinGW is in your path, something like this should work.
You might want to specify the paths to program.cpp or .exe, etc.Code:g++ program.cpp -o program.exe program.exe
You can also compile multiple files this way, by specifying more than one .cpp file -- or you can only compile the .cpp files that need compiling . . . but you quickly lose track of which ones need recompiling and which ones do not.
If you start using multiple source files, use make. Even if you're only using one source file, a Makefile can make (sorry) your life a lot easier.
Here's a very simple makefile to compile program.cpp into program.exe.
Save that as "Makefile", type make, and bam, away you go. (Or call it whatever and use make -f whatever.)Code:program.exe: program.o g++ program.o -o program.exe program.o: program.cpp g++ -c program.cpp
Note that you have to use tabs in Makefiles. Not spaces.
If you want to learn more, find a make tutorial. There are lots out there.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
So what happens if the compilation fails?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Well i was trying to do that but not able to what i need is to call the compiler through the bat file and pass my c program on command line and execute it ......well i know how to do it on command line its very simple
its like
c:\dev-cpp\bin gcc -o c:\project\embeddprogram c:\project\embeddprogram.c
it orks fine through command line
but when i am trying to create the batch file with this its not working ....
so i want help to find out how can i make the .bat file that will call the gcc compiler and compile my c programm....
Can you be more specific than "it doesn't work".
Does it for example complain about not being able to find gcc.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.