Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

compiling simple C++ program

hi,

I just bought a book "C++ Primer" and it started out with simple program

int main()
{
   return 0;
}

and the authors say that I have to compile this program using the following command at the command prompt window

c:\directory> cl -GX prog1.cpp

I tryed and it didn't work... any thoughts..?
0
davidlars99
Asked:
davidlars99
  • 9
  • 8
  • 8
2 Solutions
 
AxterCommented:
Hi davidlars99,
> >I tryed and it didn't work... any thoughts..?

Do you have a compiler?
If so, what compiler do you have?
Is your compiler in the default DOS path$ settings?

If not, you need to either add your compiler to the DOS environmental PATH$ variable, or you need to run that command using the same path that the compiler is in.

David Maisonave :-)
Cheers!
0
 
jkrCommented:
Actually

cl prog1.cpp

will work just fine. What errors are you getting?
0
 
AxterCommented:
If you don't have a compiler, you can download one of the following free compilers:
DevC++: http://www.bloodshed.net/

http://visual-mingw.sourceforge.net/ (IDE ONLY)  use with MinGW compiler

http://www.mingw.org/index.shtml (MinGW compiler only)

http://community.borland.com/cgi-bin/surveys/thanx.cgi?compiler55down (Borland Compiler only)

http://www.delorie.com/ (DJGPP compiler only)

http://www.digitalmars.com/ (Digital Mars compiler only)

http://www.openwatcom.org/ (Watcom  compiler and IDE)

http://www.gnu.org/software/gcc/gcc.html (GCC compiler)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
davidlars99Author Commented:
thanks guys... I have visual studio installed, but I do not want to use it until I master some basics of c++ lang.
0
 
AxterCommented:
I recommend DevC++
If you use a compiler with an IDE, then you can enter your code using the IDE editor, and compile your code from the IDE menu.
0
 
AxterCommented:
davidlars99,
> >thanks guys... I have visual studio installed, but I do not want to
> >use it until I master some basics of c++ lang.

What version do you have?

You should be able to do this by going to the DOS prompt, and changing your current path to the path where your cl.exe file is located at.


David Maisonave :-}
0
 
jkrCommented:
>> I have visual studio installed

That's what I tested it with - what errors are you getting when executing

cl prog1.cpp

?
0
 
davidlars99Author Commented:
@ will work just fine. What errors are you getting?

'cl' is not recognized as an internal or external command,
operable program or batch file.


I guess I need to declare a path variable, but I don't know where it is
0
 
davidlars99Author Commented:
I'm searching for it......
0
 
AxterCommented:
cl.exe should be in a path similar to the following:

C:\Program Files\Microsoft Visual Studio\VC98\Bin


You can do the following on the command prompt:
cd "C:\Program Files\Microsoft Visual Studio\VC98\Bin"
cl prog1.cpp

Or you can just do this:

"C:\Program Files\Microsoft Visual Studio\VC98\Bin\cl.exe" prog1.cpp

Either one should work, if the above path is correct for your computer.
0
 
jkrCommented:
If you have visual studio installed, the compiler's path should be set in your environment variables. If not, go to 'My Computer', choose 'Properties' and go to the 'Extended' tab. There, click on 'Environment variables' and check PATH. Also, since you're already there, look for 'INCLUDE' and 'LIB'. If they're also missing, something *really* went wrong during the installation.
0
 
jkrCommented:
>>Or you can just do this:
>>"C:\Program Files\Microsoft Visual Studio\VC98\Bin\cl.exe" prog1.cpp

IMHO that's fighting the sympoms, not the problem The next Q will then be "My compiler does not recognize any include files". If the compiler is not present in the PATH environment, something went wrong.
0
 
AxterCommented:
FYI:
On Windows 2000, that option is under "Advanced Tab" and not "Extended Tab".
0
 
davidlars99Author Commented:
yep..! that's where it was

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin

but I'm getting this error

http://www.frozendev.com/cpp.jpg
0
 
AxterCommented:
>>If the compiler is not present in the PATH environment, something went wrong.

I've rarely seen the path get populated with MS VC++ path, and I've worked on many different computers in many different locations and companies.
0
 
AxterCommented:
If you want to do this from the command prompt, you're going to have to go with jkr's advise, and add all the paths to the PATH environmental variable.

This includes BIN, INCLUDE, and LIB paths.
You'll find most of these path defined in your IDE in one of the option settnigs.
0
 
jkrCommented:
Try to locate that file and add it's folder to the PATH also.
0
 
davidlars99Author Commented:
I've added path to PATH variable

my INCLUDE
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\include\

my LIB
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\lib\

and still getting the same error
0
 
davidlars99Author Commented:
in this error "mspdb71.dll" was not found and I've added it to the PATH and ran the following, but I got errors


C:\>cl prog1.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

prog1.cpp
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:prog1.exe
prog1.obj
LINK : fatal error LNK1104: cannot open file 'LIBC.lib'

C:\>
0
 
jkrCommented:
>>LINK : fatal error LNK1104: cannot open file 'LIBC.lib'

That's why I mentioned to also check the 'INCLUDE' and 'LIB' variables - they should point to the 'include' or 'lib' directory of VS respectively.
0
 
jkrCommented:
BTW, you could also execute 'vcvars32.bat' from the compiler's 'bin' directory to set 'LIB' and 'INCLUDE' for you, but IMHO it's better to set them in the environment persistently.
0
 
davidlars99Author Commented:
these are the only paths they contain, do I something else too?

my INCLUDE
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\include\

my LIB
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\lib\
0
 
jkrCommented:
They should be enough for the moment. You could also start VS and check what other paths are set for the IDE.
0
 
davidlars99Author Commented:
I got it... I added

C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib

C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
0
 
davidlars99Author Commented:
thanks to both of you...  :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 9
  • 8
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now