Hello world!

G

Guest

First time for everything..

Installed Cbuilder from Borland, and try to build the helloworld program
(below) that pops up when I start cbuilder. When building, I get this:

g++ -c -o /usr/local/CBuilderX/samples/welcome/linux/Release_Build/main.o
-MD -I/usr/include -I/usr/include/g++-3 HelloWorld/main.cpp
HelloWorld/main.cpp: In function `int main(int, char**)':
"main.cpp": HelloWorld/main.cpp error: `cout' undeclared in namespace
`std' at line 6
"main.cpp": HelloWorld/main.cpp error: `endl' undeclared in namespace
`std' at line 6
"main.cpp": HelloWorld/main.cpp error: `cout' undeclared in namespace
`std' at line 7
"main.cpp": HelloWorld/main.cpp error: `cin' undeclared in namespace `std'
at line 9
"main.cpp": HelloWorld/main.cpp error: `cout' undeclared in namespace
`std' at line 11
"main.cpp": HelloWorld/main.cpp error: `endl' undeclared in namespace
`std' at line 11
GNU C++ Compiler exited with error code: 1
Build cancelled due to errors


However, if I remove the "-I/usr/include/g++-3" option, it builds and runs
ok. The compile options are default in cbuilder. The g++-3 directory is
present, and readable. Could someone please shed some light on this?


[main.c]
#include <iostream>
#include "main.h"

int main(int /*argc*/, char* /*argv*/[])
{
std::cout << "Hello world!" << std::endl;
std::cout << "Please enter a character and press return:";

std::cin.get();

std::cout << "Goodbye world!" << std::endl;
return 0;
}
[/main.c]


[main.h]
#if !defined(__main_h)
#define __main_h

#endif
[/main.h]
 
V

Victor Bazarov

Bjørnar Libæk said:
First time for everything..

Installed Cbuilder from Borland, and try to build the helloworld
program (below) that pops up when I start cbuilder. When building, I
get this:
[...]
Build cancelled due to errors


However, if I remove the "-I/usr/include/g++-3" option, it builds and
runs ok. The compile options are default in cbuilder. The g++-3
directory is present, and readable. Could someone please shed some
light on this?

Somebody in a C++Builder newsgroup should be able to. This really has
nothing to do with the language itself and everything with installations
of some products. Off-topic here.
 
G

Guest

On Thu, 13 Jan 2005 12:09:43 -0500, Victor Bazarov
Somebody in a C++Builder newsgroup should be able to. This really has
nothing to do with the language itself and everything with installations
of some products. Off-topic here.

Sorry, I was sloppy. But I think it's more like a g++ question, though..
Forgot to mention that same thing happens when running g++ directly from
command line. Thanks anyway:)
 
W

Will Twentyman

Bjørnar Libæk said:
First time for everything..

Installed Cbuilder from Borland, and try to build the helloworld
program (below) that pops up when I start cbuilder. When building, I
get this:

g++ -c -o
/usr/local/CBuilderX/samples/welcome/linux/Release_Build/main.o -MD
-I/usr/include -I/usr/include/g++-3 HelloWorld/main.cpp
HelloWorld/main.cpp: In function `int main(int, char**)':
"main.cpp": HelloWorld/main.cpp error: `cout' undeclared in namespace
`std' at line 6
"main.cpp": HelloWorld/main.cpp error: `endl' undeclared in namespace
`std' at line 6
"main.cpp": HelloWorld/main.cpp error: `cout' undeclared in namespace
`std' at line 7
"main.cpp": HelloWorld/main.cpp error: `cin' undeclared in namespace
`std' at line 9
"main.cpp": HelloWorld/main.cpp error: `cout' undeclared in namespace
`std' at line 11
"main.cpp": HelloWorld/main.cpp error: `endl' undeclared in namespace
`std' at line 11
GNU C++ Compiler exited with error code: 1
Build cancelled due to errors

It looks like iostream didn't get loaded. Perhaps there's an error with
the location of your include files?
However, if I remove the "-I/usr/include/g++-3" option, it builds and
runs ok. The compile options are default in cbuilder. The g++-3
directory is present, and readable. Could someone please shed some
light on this?


[main.c]
#include <iostream>
#include "main.h"

int main(int /*argc*/, char* /*argv*/[])
{
std::cout << "Hello world!" << std::endl;
std::cout << "Please enter a character and press return:";

std::cin.get();

std::cout << "Goodbye world!" << std::endl;
return 0;
}
[/main.c]


[main.h]
#if !defined(__main_h)
#define __main_h

#endif
[/main.h]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top