Solved

Compiling errors.

Posted on 1997-12-07
28
316 Views
Last Modified: 2010-04-10
I use visual c++ 4.  I got a book with it and I am trying to get the first program to compile.  It gives me an error and I don't know where to find what error it is.  It looks like this in the debugging window:  first.obj - error(s) 1, warning(s) 0.  I want to know what is wrong?
this is the code:

#include <iostream.h>

int main()
{
      cout << "Hello World!";
      cout << endl;
      return 0;
}
0
Comment
Question by:Etrain
  • 9
  • 7
  • 4
  • +8
28 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1175101
That code compiled and ran fine for me.
0
 
LVL 2

Expert Comment

by:mitchell042997
ID: 1175102
Are you compiling it in a project, which is expecting WinMain?  If you check, when you go to "New File", you can choose an option called something like "console mode" where you can program old DOS C++ programs.  Try going there and using the code yo supplied.  (As is, the code you have shown is error-free for DOS C++.)
0
 
LVL 1

Expert Comment

by:TKII
ID: 1175103
Try to set up a project for this. You can use the AppWizard for this. Go to the File menu. There should be something like create new workspace or project or something. When you have your project then create your source code file and add it to the project. try compiling again (or build the project). Your code is ok, it should run.
For this hello world stuff you should use a console app.
0
 

Author Comment

by:Etrain
ID: 1175104
Even if I use the console mode it still gives me an error.  Is there any way to tell what the error is?
0
 
LVL 3

Expert Comment

by:LucHoltkamp
ID: 1175105
You also need to include iomanip.h which defines endl. Add

#include <iomanip.h>

.luc.
0
 

Author Comment

by:Etrain
ID: 1175106
even when I add that it does not work.  Sorry...
0
 

Expert Comment

by:gunn
ID: 1175107
I had this type of stupid problem earlier today just wizzing up a sample test code.

Pick File..New...and pick "Console App" from the list you get. Give your project a name. When thats finished, you will have no files in the project. Pick File..New.. and pick C/C++ source file, make sure the checkmark is checked to add this file to the current project and give it a name.

Now, put the code you have above in that new file and save it. Now, just compile the file: is that ok?

Now, "Build" the project.  That should do it.

If you *still* get an error, please select and copy the error you are getting in the window at the bottom of VisualC++ and paste it in here so we can help you better.

Hope that helps.

0
 

Expert Comment

by:miredo
ID: 1175108
The following sequence of actions worked for me:

1) click File, New, Text File
2) Type in your code.
3) click Build, Build
4) Answer 'yes' to "Would you like to create a default project workspace?"
5) Type in a name and save.
6) click Build, Execute <your filename>.exe

The following appears in a DOS box:

Hello, World!
Press any key to continue_

0
 

Author Comment

by:Etrain
ID: 1175109
I tried this many times, but it still gives me an error and I don't no where the error is.  Could anyone tell me where to find what the error is?
0
 

Expert Comment

by:gunn
ID: 1175110
Its in the bottom of the MSVC++ window dialog! You'll see the compiler and linker statements. Any errors you get will show up there.
what are they...please post them.
0
 

Author Comment

by:Etrain
ID: 1175111
It just tells me that I have an error but doesn't tell me were it is or what it is.  Is there something that I need to turn on so it will show them?  
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175112
Are you looking at the output window?  The output window lists the errors.  It could be covered by the infoviewer or other window.
0
 

Author Comment

by:Etrain
ID: 1175113
--------------------Configuration: hello -Win32 Debug------------
hello.exe - 1 error(s), 0 warning(s)

this is what the screen looks like.  Could anyone tell me what is wrong?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175114
No.  But maybe we can learn something from a different dirrection.  Try to cause an error and see what happens.  Put in a syntax error and see if the compiler reports it or just the "phantom error".

If you are new to C, you can change the "int" returned from maint to be "Int" (capital I) that should cause a problem (and you were hoping to fix one...)
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 22

Expert Comment

by:nietod
ID: 1175115
By the way, you ARE looking at the right place.  Between the lines you posted there SHOULD be one line that lists the error.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175116
Actually, there should be at least two lines between what you posted.  I may have an idea of what your problem is.

Do you have a workspace (project) open and do you have the source code file in the projects?
0
 

Author Comment

by:Etrain
ID: 1175117
Yes the files are in a project.  Even if I try to put in errors it does not catch them only the configuration error.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175118
That's interesting.  I think that means that it doesn't even start to compile.  It should print a message that says
"compiling XXXXXX" between the two lines you posted.

There must be something wrong with your workspace.  

You could try creating a new workspace and see what happens.

Do you know if you are creating the workspace correctly?  Unfortunatly, I can't imagine what you could be doing wrong.  Did you choose a console application project type?  Can you see the source code file in the workspace window?

If necessary, you could contact Microsoft technical support.  They will almost certainly be able to help you, but it will cost.
0
 

Author Comment

by:Etrain
ID: 1175119
Yes everything is alright with the workspace.  I really didn't want to ask Microsoft, but it might be the only thing to do.  Thanks....
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175120
Well I'm pretty sure the problem is occurring BEFORE it starts to compile your source code.  That's why it does not list the source file and does not list the intentional errors in the source.

What does a compiler do before it compiles?  
0
 

Expert Comment

by:gunn
ID: 1175121
Yes, something is wrong before the compile. I think I had an error like that before, but can't remember specifics...

Start a new Project. Pick New... from the FILE menu and pick 'Console App'. Then, just add the .c file you have created to your project...and thats all. Start with a completely new project, and only save the .c file. Actually, why don't use just type it over again? Its small enough. That way you start fresh. See if that makes the error go away.

If not, then I would suggest uninstalling MSVC++ and then reinstalling it again....


0
 
LVL 1

Expert Comment

by:SvenT
ID: 1175122
--------------------Configuration: hello -Win32 Debug------------
hello.exe - 1 error(s), 0 warning(s)

Has nothing scrolled away from your output window? (have you
checked with the scroll bar?) The error may be something like
"Can't find CL.EXE"

Can you compile your file from a command prompt? (CL HELLO.C)
If not, reinstall MSVC++

Hope this helps!
0
 

Expert Comment

by:TheTomer
ID: 1175123
It sounds to me like an MSVC configuration problem:
1) is there enough disk space?
2) did you name the file with a ".cpp" extension and save it?
3) can you compile any other program (maybe in "c") like:
#include <stdio.h>
void main() { printf("hello, world!\n"); }

0
 

Author Comment

by:Etrain
ID: 1175124
I will try these once I get back to school.  Right now I am awy from my usual computer and stuck on another slower computer.

Thanks again.
Etrain
0
 

Author Comment

by:Etrain
ID: 1175125
Well, when I got back to school, my system wouldn't boot so I had to dump everything and start over.  The program now runs and is working great.  Thanks for the help.
Etrain......
0
 

Expert Comment

by:gunn
ID: 1175126
Now thats what we told ya to do in the beginning....start over!

Glad its fixed.
0
 
LVL 10

Accepted Solution

by:
rbr earned 70 total points
ID: 1175127
try
int main (int argn, char argv[])
{
...
}
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175128
You don't have to specify arguments to main and the problem was that the MSVC was corrupted or installed incorrectly.  The problem is fixed.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now