We help IT Professionals succeed at work.

Check out this week's podcast, "Dairy Farms to Databases: Community's Hand in Technology"Listen Now

x

Compiling errors.

Etrain
Etrain asked
on
347 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;
}
Comment
Watch Question

ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
That code compiled and ran fine for me.
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++.)

Commented:
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.

Author

Commented:
Even if I use the console mode it still gives me an error.  Is there any way to tell what the error is?
You also need to include iomanip.h which defines endl. Add

#include <iomanip.h>

.luc.

Author

Commented:
even when I add that it does not work.  Sorry...

Commented:
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.

Commented:
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_

Author

Commented:
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?

Commented:
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.

Author

Commented:
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?  

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

Author

Commented:
--------------------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?

Commented:
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...)

Commented:
By the way, you ARE looking at the right place.  Between the lines you posted there SHOULD be one line that lists the error.

Commented:
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?

Author

Commented:
Yes the files are in a project.  Even if I try to put in errors it does not catch them only the configuration error.

Commented:
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.

Author

Commented:
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....

Commented:
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?  

Commented:
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....


Commented:
--------------------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!

Commented:
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"); }

Author

Commented:
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

Author

Commented:
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......

Commented:
Now thats what we told ya to do in the beginning....start over!

Glad its fixed.
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
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.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.