PDA

Click to See Complete Forum and Search --> : Borland Errors


Hooligan
Nov 21st, 2002, 12:45 AM
#include <iostream.h>

int main()

{

cout<<"HEY, you, I'm alive! Oh, and Hello World!";

return 0;

}

Been looking through Tutorial sites and just copy pasted the code over everything and I get two error's when I try to run the program...

[Linker Error] Unresolved external '_Form1' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER6\PROJECTS\PROJECT2.OBJ
[Linker Error] Unresolved external 'TForm1::' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER6\PROJECTS\PROJECT2.OBJ

Any reason for this? Was there something I shouldn't have pasted over for it to run?

The Hobo
Nov 21st, 2002, 09:40 AM
I don't know why you're getting the errors, but don't use <iostream.h>

#include <iostream>
using namespace std;

int main() {

cout << "HEY, you, I'm alive! Oh, and Hello World!";

return 0;

}

parksie
Nov 21st, 2002, 10:24 AM
Most people using C++ Builder have trouble. It's not setup for "normal" C++ use, it assumes you're using the GUI (which is, obviously, not what you want in this instance).

Apparently there was a way, but I'd need a copy to work it out, and I can't be bothered to boot back into Windows again.

FunyBunyFartAHH
Nov 21st, 2002, 10:59 AM
Well see this is how I do it for a Simple Hello World Proggy:

#include <iostream.h>

main() //notice no int before main, you dont need it
{
cout << "Hello Wolrd" << endl;
return(0); // notice brackets around 0
}

parksie
Nov 21st, 2002, 11:04 AM
6 mistakes:

1. <iostream> not <iostream.h>, the latter is deprecated.

2. No "using namespace std;" -- everything in the Standard C++ Library is within that namespace.

3. You *do* need the int. Implicit int was dropped because it caused trouble, and was totally incompatible with the type checking. It's since been dropped from C as well.

4. You misspelled "World".

5. No return statement is necessary in main(), and the parentheses aren't necessary either.

6. ( ) == Parentheses. [ ] = Brackets. { } = Braces.


:)

The Hobo
Nov 21st, 2002, 11:04 AM
Originally posted by FunyBunyFartAHH
Well see this is how I do it for a Simple Hello World Proggy:

#include <iostream.h>

main() //notice no int before main, you dont need it
{
cout << "Hello Wolrd" << endl;
return(0); // notice brackets around 0
}

Why do you use iostream.h? :confused:

And if you're going all gung ho about not needing int before main, perhaps you will take notice that there's no need for brackets around 0.

The Hobo
Nov 21st, 2002, 11:06 AM
Originally posted by parksie
...

You beat me to the punch, but regarding #5, I get a compiler error when not returning anything from main (when declared as int). What compiler do you use?

The Hobo
Nov 21st, 2002, 11:07 AM
Originally posted by The Hobo
You beat me to the punch, but regarding #5, I get a compiler error when not returning anything from main (when declared as int). What compiler do you use?

I get that error in VC++. I just tried with Borland and no error.

So hats off to you. Just compiler differences.

parksie
Nov 21st, 2002, 11:08 AM
GCC 3.2. VC++7 works as well.

The non-requirement for a return statement is part of the C++ standard -- if you don't return anything, the compiler is obliged to insert the equivalent to "return 0".

FunyBunyFartAHH
Nov 21st, 2002, 11:23 AM
My bad, its borland, I use visual, and my bad for the world spelling error ; /

The Hobo
Nov 21st, 2002, 11:29 AM
Originally posted by FunyBunyFartAHH
My bad, its borland, I use visual, and my bad for the world spelling error ; /

Regardless of your compiler, the code is still...crap.