LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 06-10-2006, 09:23 AM   #1
adilturbo
Member
 
Registered: Jun 2006
Location: morocco
Posts: 195

Rep: Reputation: 30
pblm with std::cout while compiling


i have mandrake 10.1 linux OS and gcc-3.4.1-4mdk version.

so i wrote just a sample prog to test gcc ,in that prog i used
Quote:
std::cout<<"hello"<<'\n';
instruction.
so while compiling i got messages telling errors with std
like this:

Quote:
[root@localhost adil]# gcc cpp/class.cpp -o class
In file included from cpp/class.cpp:2:
cpp/class.h:22:3: warning: no newline at end of file
cpp/class.cpp:7:2: warning: no newline at end of file
/root/tmp/ccpxKxtZ.o(.text+0xd): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
/root/tmp/ccpxKxtZ.o(.text+0x60): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >:perator[](unsigned int) const'
/root/tmp/ccpxKxtZ.o(.text+0x9d): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >:perator[](unsigned int) const'
/root/tmp/ccpxKxtZ.o(.text+0xc8): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >:perator[](unsigned int) const'
/root/tmp/ccpxKxtZ.o(.text+0x154): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init()'
/root/tmp/ccpxKxtZ.o(.text+0x183): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init()'
/root/tmp/ccpxKxtZ.o(.gnu.linkonce.t._ZN1a4drawEv+0x14): In function `a::draw()':
: undefined reference to `std::cout'
/root/tmp/ccpxKxtZ.o(.gnu.linkonce.t._ZN1a4drawEv+0x19): In function `a::draw()':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/root/tmp/ccpxKxtZ.o(.gnu.linkonce.t._ZN1a4drawEv+0x22): In function `a::draw()':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)'
/root/tmp/ccpxKxtZ.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
plz i need some help. thank u

Last edited by adilturbo; 06-10-2006 at 09:25 AM.
 
Old 06-10-2006, 09:36 AM   #2
worzel68
Member
 
Registered: May 2006
Location: Sydney
Distribution: FC5, FC3, AIX, System V,
Posts: 50

Rep: Reputation: 15
Do you have the code

Quote:
using namespace std
near the top of you file ?

You could use cout without the std:: namespace resolution operator, provided you inclide the stdio header file like this:

#include <stdio>

Does this help ? If not send us some code.

Cheers.
 
Old 06-10-2006, 09:50 AM   #3
adilturbo
Member
 
Registered: Jun 2006
Location: morocco
Posts: 195

Original Poster
Rep: Reputation: 30
no sorry. the same pblm exist.

i used the
Quote:
using namespace std;
instruction before,
i got the same messages, itried with including the stdio header file,
the same problem.
is there an other solustion?
 
Old 06-10-2006, 09:55 AM   #4
worzel68
Member
 
Registered: May 2006
Location: Sydney
Distribution: FC5, FC3, AIX, System V,
Posts: 50

Rep: Reputation: 15
Can you send some of your code? If it is too big then send the first page with the includes and then the lines surrounding the std::cout call.
 
Old 06-10-2006, 10:09 AM   #5
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You should be using g++ to compile C++ code.
 
Old 06-10-2006, 10:21 AM   #6
worzel68
Member
 
Registered: May 2006
Location: Sydney
Distribution: FC5, FC3, AIX, System V,
Posts: 50

Rep: Reputation: 15
Here is some code I found in KDevelop Documentation

Quote:
#include <iostream>

using namespace std;

int main()
{
int ival;
char sval[30];

cout << "Enter a number:" << endl;
cin >> ival;
cout << "And now a string:" << endl;
cin >> sval;

cout << "The number is: " << ival << endl
<< "And the string is: " << sval << endl;
}
Apologies, I told you about the wrong include file.

Oh Yeah, as Nylex says using g++ - that would be really good!!!
 
Old 06-10-2006, 11:32 AM   #7
adilturbo
Member
 
Registered: Jun 2006
Location: morocco
Posts: 195

Original Poster
Rep: Reputation: 30
thank u so much .
it works now with g++.
thank u again Nylex and worzel68
 
Old 06-12-2006, 08:56 AM   #8
RoughEdge
Member
 
Registered: Jan 2004
Location: Scotland
Distribution: Slackware 12
Posts: 67

Rep: Reputation: 15
I am sure that when using

Code:
 #include <iostream>
You need to use

Code:
 #include <iostream>

using namespace std;

.
.
If you leave out the using namespace std, then you will always need to use std::cout.

You can also use #include <iostream.h>, which negates the need to use the using namespace std; but I am sure that it is better practice to use <iostream>, I think that is the proper C++ header as opposes to a C header. I have never used <iostream.h> on linux so am unsure if it is included.

Hope that helps
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Not comiling right!?!? fleshwound Linux - General 7 01-21-2006 10:32 PM
Help Me Out.. Pblm With Grub fpfernando Linux - Newbie 3 10-24-2005 12:12 AM
`cout' undeclared in namespace `std' aw_wolfe Programming 1 04-30-2005 10:25 PM
Font pblm ? redshadow Linux - Software 1 02-06-2004 06:50 AM
Mozilla 1.6 pblm JIV Linux - Software 2 02-01-2004 06:07 PM


All times are GMT -5. The time now is 01:05 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration