LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-07-2003, 05:56 PM   #1
rob99
Member
 
Registered: Jan 2003
Posts: 50

Rep: Reputation: 15
gcc with iostream problem


Hi All,
Just started on linux and like to write some c++ programs,
but in the very beginning I was stopped on something simple
I think:
#include <iostream.h>
int main()
{
cout<<"test";
}
when I use gcc test.cpp ,
I'm getting error: "undefine reference to std::cout"
On windows I don't have problems with that.

thanks
 
Old 04-07-2003, 06:42 PM   #2
macewan
Senior Member
 
Registered: Jan 2002
Distribution: Ubuntu, Debian
Posts: 1,055
Blog Entries: 1

Rep: Reputation: 45
(disclaimer: I AM NOT A PROGRAMMER!)

vi bob.C
[type in the bob program]
:wq
g++ -Wno-deprecated bob.C -o bob
./bob
 
Old 04-07-2003, 06:59 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
That's a linker error mate ...

Could you please copy & paste
exactly what you did to get there,
a description of you distro and the
gcc version would be nice to know,
too .. :)

Cheers,
Tink
 
Old 04-07-2003, 07:57 PM   #4
rob99
Member
 
Registered: Jan 2003
Posts: 50

Original Poster
Rep: Reputation: 15
macewan,
thanks, it works now, but why gcc doesn't want?
I can use g++, but I thought that gcc is c++ compiler.
thanks!
 
Old 04-07-2003, 08:19 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Read man gcc :) and find out that you thought
wrong...

Cheers,
Tink
 
Old 04-07-2003, 08:58 PM   #6
macewan
Senior Member
 
Registered: Jan 2002
Distribution: Ubuntu, Debian
Posts: 1,055
Blog Entries: 1

Rep: Reputation: 45
Quote:
Originally posted by rob99
macewan,
thanks, it works now, but why gcc doesn't want?
I can use g++, but I thought that gcc is c++ compiler.
thanks!
don't know the answer. I am not a programmer. Currently teaching myself c++ and that works for me : ) so I used it instead of gcc
 
Old 04-10-2003, 02:12 PM   #7
kenulla
LQ Newbie
 
Registered: Apr 2003
Posts: 13

Rep: Reputation: 0
Quote:
Originally posted by rob99
macewan,
thanks, it works now, but why gcc doesn't want?
I can use g++, but I thought that gcc is c++ compiler.
thanks!
gcc can compile many languages, it used to stand for gnu c compiler but now it has been changed to gnu compiler collection, you were experiencing a linking problem.
g++ is a program that invokes gcc with the default language set to C++ and automatically links to c++ libraries
 
Old 04-16-2003, 06:56 PM   #8
Pwcca
Member
 
Registered: Jan 2003
Location: Florida, USA
Distribution: Slackware
Posts: 169

Rep: Reputation: 30
cant you specify a language for gcc to compile with the -x option?
 
Old 04-16-2003, 07:16 PM   #9
macewan
Senior Member
 
Registered: Jan 2002
Distribution: Ubuntu, Debian
Posts: 1,055
Blog Entries: 1

Rep: Reputation: 45
#include <iostream.h>
int main()
{
cout << "test";
return 0;
}




///////////////////////
i have to return 0 in the case above.
 
Old 04-16-2003, 09:56 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally posted by Pwcca
cant you specify a language for gcc to compile with the -x option?
Yes you can...

-x language
Specify explicitly the language for the following
input files (rather than choosing a default based
on the file name suffix) . This option applies to
all following input files until the next `-x' op-
tion. Possible values of language are `c', `objec-
tive-c', `c-header', `c++', `cpp-output', `assem-
bler', and `assembler-with-cpp'.

Cheers,
Tink
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
g++ compiler and iostream.h BACTRATE Mandriva 5 07-26-2009 04:12 AM
gcc vs. g++ -> iostream lib found vs. not found CooManChu Linux - General 1 12-11-2004 09:20 AM
c to GCChange of member functions in iostream from GCC296 to Gcc 3.2.2 Basiltp Programming 0 11-29-2004 03:19 PM
where is iostream invisibleghost Programming 2 10-24-2004 01:30 PM
GCC:- 'cout' is an undeclared function when #include <iostream> is included? caesius_01 Programming 5 04-04-2004 11:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration