Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-24-2002, 10:48 PM   #1
Registered: Oct 2002
Location: At my desk...
Distribution: RedHat, Fedora, Ubuntu
Posts: 344

Rep: Reputation: 30
Help with C/C++ compiler please...

Ok, i have already searched through the newbie forum for the answer to this so hold your flames...

I have been programming in C/C++ for quite some time now but have never done so in a Linux environment.

I have just installed Red Hat 8.0 and am using the KDE GUI.

I am trying to compile and run a simple hello world program with this code:

#include <iostream.h>

int main()
cout << "Hello World!" << endl;
return 0;

Simple enough right? Below is the output I get when I try to compille it. Please help me make since of what it is I need to do to produce C/C++ programs in a Linux Environment.

[wbsmith2@dhcppc1 programs]$ gcc -o hello hello.cpp
In file included from /usr/include/c++/3.2/backward/iostream.h:31,
from hello.cpp:1:
/usr/include/c++/3.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
/tmp/ccYveVmw.o: In function `main':
/tmp/ccYveVmw.o(.text+0x14): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/tmp/ccYveVmw.o(.text+0x21): undefined reference to `std::cout'
/tmp/ccYveVmw.o(.text+0x26): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccYveVmw.o(.text+0x2f): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccYveVmw.o: In function `__static_initialization_and_destruction_0(int, int)':
/tmp/ccYveVmw.o(.text+0x5c): undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccYveVmw.o: In function `__tcf_0':
/tmp/ccYveVmw.o(.text+0x8b): undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccYveVmw.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
[wbsmith2@dhcppc1 programs]$ ls

thanks in advance...
Old 10-24-2002, 11:06 PM   #2
Registered: Oct 2002
Location: At my desk...
Distribution: RedHat, Fedora, Ubuntu
Posts: 344

Original Poster
Rep: Reputation: 30
ok, i figured part of this out....

first off, it appears as if I should be using the g++ compiler instead of the gcc compiler...

when I was at school it never seemed to matter...

/me shrugs

next, to run the executable type "./a.out" or whatever it is named

in my case it was "./hello"

now, can anyone help me out with why <iostream.h> contains a deprecated header?
Old 10-24-2002, 11:14 PM   #3
Registered: Oct 2002
Distribution: RH 8.0 and fluxbox
Posts: 122

Rep: Reputation: 15
trying using "#include <iostream>" without the .h, then you won't get the error message. As for why iostream.h is old or whats new in iostream, i couldn't tell you.
Old 10-24-2002, 11:34 PM   #4
Registered: Oct 2002
Location: At my desk...
Distribution: RedHat, Fedora, Ubuntu
Posts: 344

Original Poster
Rep: Reputation: 30
thanks man....

that and this line needs to be added;

using namespace std;

WTF! i just graduated in May(BS in Comp Engineering) and NEVER was I introduced to this nor did I ever have to use it...
Old 10-25-2002, 04:12 AM   #5
Registered: Jul 2002
Location: Santa Cruz, CA
Distribution: lfs
Posts: 538

Rep: Reputation: 30
that "using namespace std;" is in my c++ book... but I never have to use it. I think it just tells the compiler to look in the "standard" place for the header files.

you're right on with the ./a.out . in the *nix systems, a "." means "current directory" and ".." means next directory up. so if you want to use an executable from your current directory, you do ./ . if you make another directory in there and change into it (cd), you can run that same binary with ../a.out. or, cd back up with cd .. ( or cd ../ to go along with what's stated above)

if you want to just be able to use your programs from anywhere on your system without having to type the full path, you need to put it in /bin, /usr/bin, or anything that gets spit out when you do "echo $PATH". you can also make a directory for only your programs and add that directory to your $PATH variable. open up the file ~/.bash_profile (files and directories w/ a "." in front of them are "hidden"... to see them all when you are in that directory do "ls -a").... also the "~/" means "home directory"... bash understands what you are talking about. this will be /root for the root user and /home/user for any other user.... ooh yeah.. back to $PATH.... open up your ~/.bash_profile, and you'll see a line like PATH=/bin:/usr/bin:, ect.. just put your personal program directory at the end and make sure each of the paths are separated by a colon.

well, have fun!


p.s.- if you have gcc 3.1 (find out with gcc -v) there is a bug in <string.h>, so if you're planing on using that... you should upgrade to gcc-3.2

Last edited by adam_boz; 10-25-2002 at 04:15 AM.
Old 10-25-2002, 06:11 AM   #6
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,684

Rep: Reputation: 230Reputation: 230Reputation: 230
Well, you're naming a C program as a C++ program. It creates trouble. Rename the file to hello.c and it will compile without a warning.


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
checking for C compiler default output... configure: error: C compiler cannot create fiorejm Linux - Software 6 11-12-2009 01:35 PM
C++ IDE+Compiler?Java IDE+compiler? Boby Linux - Software 3 05-31-2005 02:12 PM
Compiler conundrum: Which came first, a compiler, or it's source code? fr0zen Programming 21 01-29-2004 05:31 AM
No compiler to compiler the compliler NewtonIX Linux - Newbie 13 11-03-2003 06:32 AM
compile a compiler without a compiler? lackluster Linux - General 18 01-02-2003 08:55 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:59 AM.

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