473,327 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

what's wrong with this helloworld program?

ben
When I try to gcc the following Helloworld program:

#include <iostream>

int main()
{
using namespace std;
cout << "Hello, World!!\n";
return 0;
}

I got errors as follows:

C:\Documents and Settings\benben>gcc ben.cpp
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x33):ben.cpp: undefined
refer
ence to `std::cout'
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x38):ben.cpp: undefined
refer
ence to `std::basic_ostream<char, std::char_traits<char> >& std::operator<<
<std
::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&,
char c
onst*)'
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x64):ben.cpp: undefined
refer
ence to `std::ios_base::Init::Init()'
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x83):ben.cpp: undefined
refer
ence to `std::ios_base::Init::~Init()'

What has happend? Could anyone help me?
Jul 23 '05 #1
15 1468
ben wrote:
When I try to gcc the following Helloworld program:

#include <iostream>

int main()
{
using namespace std;
cout << "Hello, World!!\n";
return 0;
}

I got errors as follows:
snip
What has happend? Could anyone help me?


You declare "using namespace std;" inside of main()...it should be outside.

--
Alvin
Jul 23 '05 #2
"ben" <be******@hotmail.com> writes:
When I try to gcc

Try g++
?

Jul 23 '05 #3
ben wrote:
When I try to gcc the following Helloworld program:

#include <iostream>

int main()
{
using namespace std;
cout << "Hello, World!!\n";
return 0;
}

I got errors as follows:

C:\Documents and Settings\benben>gcc ben.cpp
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x33):ben.cpp: undefined
refer
ence to `std::cout'
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x38):ben.cpp: undefined
refer
ence to `std::basic_ostream<char, std::char_traits<char> >&
std::operator<< <std
::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&,
char c
onst*)'
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x64):ben.cpp: undefined
refer
ence to `std::ios_base::Init::Init()'
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x83):ben.cpp: undefined
refer
ence to `std::ios_base::Init::~Init()'

What has happend?
You used the compiler the wrong way.
Could anyone help me?


Try with g++ instead of gcc.

Jul 23 '05 #4
ben
That works! So is g++ specified for C++ programs and gcc for C programs?

ben

"Tim Love" <tp*@eng.cam.ac.uk> wrote in message
news:d6**********@gemini.csx.cam.ac.uk...
"ben" <be******@hotmail.com> writes:
When I try to gcc

Try g++
?

Jul 23 '05 #5
ben wrote:
When I try to gcc the following Helloworld program:

#include <iostream>

int main()
{
using namespace std;
cout << "Hello, World!!\n";
return 0;
}

Nothing is wrong with the program.
I got errors as follows:

C:\Documents and Settings\benben>gcc ben.cpp
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x33):ben.cpp: undefined
refer
ence to `std::cout'
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x38):ben.cpp: undefined
refer
ence to `std::basic_ostream<char, std::char_traits<char> >&
std::operator<< <std
::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&,
char c
onst*)'
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x64):ben.cpp: undefined
refer
ence to `std::ios_base::Init::Init()'
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x83):ben.cpp: undefined
refer
ence to `std::ios_base::Init::~Init()'

What has happend? Could anyone help me?


Try compiling with g++ instead of gcc.
Best

Kai-Uwe Bux
Jul 23 '05 #6
ben wrote:
That works! So is g++ specified for C++ programs and gcc for C programs?


Basically, yes. For the compiler, it doesn't matter much. g++ will assume
your code is C++, while gcc tries to detect it from the file name. However,
for linking, the difference is more important. For C++, the linker needs
some additional options (e.g. to link in the C++ standard library), and g++
adds those options, gcc doesn't.
Further questions about g++ should be asked in gnu.g++.help
Jul 23 '05 #7
ben
Thanks a lot!

ben

"Rolf Magnus" <ra******@t-online.de> wrote in message
news:d6*************@news.t-online.com...
ben wrote:
That works! So is g++ specified for C++ programs and gcc for C programs?
Basically, yes. For the compiler, it doesn't matter much. g++ will assume
your code is C++, while gcc tries to detect it from the file name.

However, for linking, the difference is more important. For C++, the linker needs
some additional options (e.g. to link in the C++ standard library), and g++ adds those options, gcc doesn't.
Further questions about g++ should be asked in gnu.g++.help

Jul 23 '05 #8
ben
I think the using namespace statement is meant to be inside a function, for
localization's sake.

"Alvin" <reply@in_newsgroup.ca> wrote in message
news:dNlie.56859$0X6.6013@edtnps90...
ben wrote:
When I try to gcc the following Helloworld program:

#include <iostream>

int main()
{
using namespace std;
cout << "Hello, World!!\n";
return 0;
}

I got errors as follows:
snip

What has happend? Could anyone help me?


You declare "using namespace std;" inside of main()...it should be

outside.
--
Alvin

Jul 23 '05 #9
ben wrote:
That works! So is g++ specified for C++ programs and gcc for C programs?


In general, yes. The programs "g++" and "gcc" both invoke the same
compiler back ends, and either will compile .cpp or .c to .o as
as appropriate (some others as well). The difference is that g++
will seed the linker with the names of the C++ libraries, etc.. where
gcc assumes you're doing only C things.
Jul 23 '05 #10
In message <42**********************@news.optusnet.com.au>, ben
<be******@hotmail.com> writes
When I try to gcc the following Helloworld program:

#include <iostream>

int main()
{
using namespace std;
cout << "Hello, World!!\n";
return 0;
}

I got errors as follows:

C:\Documents and Settings\benben>gcc ben.cpp
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x33):ben.cpp: undefined
refer
ence to `std::cout'
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x38):ben.cpp: undefined
refer
ence to `std::basic_ostream<char, std::char_traits<char> >& std::operator<<
<std
::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&,
char c
onst*)'
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x64):ben.cpp: undefined
refer
ence to `std::ios_base::Init::Init()'
C:\DOCUME~1\benben\LOCALS~1\Temp/ccojbaaa.o(.text+0x83):ben.cpp: undefined
refer
ence to `std::ios_base::Init::~Init()'

What has happend?
Those are linker errors. You haven't included the correct libraries,
probably because you started the compiler in "C" mode instead of "C++"
mode.
Could anyone help me?


Try typing g++ instead of gcc ;-)

--
Richard Herring
Jul 23 '05 #11
Ron Natalie wrote:
ben wrote:
That works! So is g++ specified for C++ programs and gcc for C programs?


In general, yes. The programs "g++" and "gcc" both invoke the same
compiler back ends, and either will compile .cpp or .c to .o as
as appropriate (some others as well).


Wrong (if by "appropriate" you mean that files with names ending in .c
should be compiled as C code). Consider this:

$ cat test.c
#include <stdlib.h>

int main()
{
int* x = malloc(sizeof(int));
free(x);
return 0;
}
$ gcc test.c
$ g++ test.c
test.c: In function `int main()':
test.c:5: error: invalid conversion from `void*' to `int*'

Jul 23 '05 #12
ben wrote:
When I try to gcc the following Helloworld program:

#include <iostream>

int main()
{
using namespace std;
cout << "Hello, World!!\n";
return 0;
}


As everyone else has pointed out - use g++ - however there might be an
error in your code.

std::basic_ostream (IIRC) is supposed to be defined in ostream, which
you do not include, hence it may not work on all compilers.

see:
http://groups-beta.google.com/group/...?output=gplain
Jul 23 '05 #13
Alvin wrote:
You declare "using namespace std;" inside of main()...it should be outside.

Actually what ben does is better.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #14
ben
In The C++ Programming Language (Special Edition) by Bjarne Stroustrup,
page46, is Bjarne's Hello, world! version. He didn't include <ostream>
either.

ben

"Gianni Mariani" <gi*******@mariani.ws> wrote in message
news:gP********************@speakeasy.net...
ben wrote:
When I try to gcc the following Helloworld program:

#include <iostream>

int main()
{
using namespace std;
cout << "Hello, World!!\n";
return 0;
}


As everyone else has pointed out - use g++ - however there might be an
error in your code.

std::basic_ostream (IIRC) is supposed to be defined in ostream, which
you do not include, hence it may not work on all compilers.

see:

http://groups-beta.google.com/group/...98c3d20?output
=gplain
Jul 23 '05 #15
* ben:
[top-posting]


Don't top-post in this group.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Maria Gaitani | last post by:
Hi! I am trying to programme some java native interface but I'm still in the process of research. I've seen examples such as this one...
5
by: IWP506 | last post by:
10 points (and a cookie) to whoever tells me why this code generates these errors: C:\Programming\Microsoft Visual Studio\MyProjects\HelloWorld\main.c(5) : error C2065: 'cout' : undeclared...
2
by: Jason Jacob | last post by:
To all I am new to MS's VC++ and got a question. I've tried to write a simple console program "HelloWorld.cpp", then I've added a simple class (Class01.h and cpp) Class01 compile well, but...
3
by: Alan Silver | last post by:
Hello, Sorry if this is a stupid question, but I can't really see much difference between these tow methods according to the scant info in the SDK. Could anyone enlighten me? TIA -- Alan...
10
by: guido.baumhoff | last post by:
Hello everybody, I am very confused: an last saturday my client has installed a new notebook system with the components, I have wish: Microsoft Windows XP, IIS 5.1, SQL MSDE with SP4, .NET...
9
by: Richard Lionheart | last post by:
Hi All, I've got Visual Studio .Net installed, but I don't know it very well. So I tried to create a plain old Win32 using the command-line complier. I tried to compile: ************...
12
by: TC | last post by:
I'm trying to figure out what the "Friend" keyword does. I know it specifies that "elements are accessible from within the same assembly", but that doesn't help because I don't know what an...
7
by: michigaki | last post by:
hello, we are having problems in compiling a 'slightly' altered x264. We are always receiving a 'helloWorld' undeclared (first use this function) error. We may be commiting a very simple error but...
13
by: notbob | last post by:
Grrr.... I'm following A Byte of Python and into the while loops chap. I cp/paste while.py to a file and give 777 perms. I mv while.py to while and run it (./while) as a standalone script. I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.