C++ compiler to behave as C compiler

Hi,
I'm using Microsoft Visual Studio 2005. Does anyone know how to compile a C++ program through command line?
Also, please let me know if it is possible to compile the same program using C compiler. I'm not sure if we can use both C and C++ compilers in Visual Studi 2005.
When Visual Studio is installed, it sets up some environment variables, VS80COMNTOOLS being one of them.

First run this to set up the environment variables:
call "%VS80COMNTOOLS%vsvars32.bat"

Use cl to compile your code:
cl /W4 hello.cpp

Alternatively, you can build a project using devenv:
devenv myfirstproject.sln /build debug
Last edited on
do i need to run call "%VS80COMNTOOLS%vsvars32.bat" through command prompt?

If I give any command like cl or devenv through command prompt, it gives error like
command not found.
Yes, it sets the path, include and lib variables. What 's the problem?
MSVS won't install for me (I still haven't figured out how to get .NET 3.5 to install on my PC), but the following should be helpful for you.

As part of using the command prompt, I keep a bunch of utilities in a directory that is added to the PATH when I open the prompt. I tend to use a specific shortcut to do it, but you can also set it to work whenever you open a command prompt. (I use the former simply to keep the command shell clean of my modifications when other programs want to open a command shell for their own purposes.)

In my utility directory ("D:\bin") I keep a file named "gcc.bat" (among others) which look something like:
1
2
@set PATH=C:\MinGW\bin;%PATH%
@gcc %*
(Remember that the %* substitution only works on NT-level kernels -- I'm on XP. If you aren't, you'll have to use %1 %2 %3 %4 etc)

That way, at the command prompt, I only need to type "gcc" to invoke the compiler, and the batch script in my utility directory runs to set up the environment needed to use it. Once activated the first time, the GCC's executables are found in the path before my script, so it isn't needed again. That is, the next time I type "gcc" to invoke the compiler, it doesn't bother with my script but just uses the compiler directly.

You can do the same sort of thing with the microsoft compiler. Keep in mind that this requires you to be careful about what is in your PATH by default when you open a command prompt.

Hope this is helpful.
Topic archived. No new replies allowed.