LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 09-26-2004, 12:02 AM   #1
lu543285
LQ Newbie
 
Registered: Jan 2004
Location: Świdnik
Distribution: Mandrake 10.0
Posts: 21

Rep: Reputation: 15
my first C++ program, errors while compiling


I'm looking for an answer for the following problem (very difficult against all appearances):

How to compile and run my first C++ program?.

Here is the code (very original..):

#include<iostream>

int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}

I run it by writing: gcc hello.cpp

Here are the errors:

/home/staszek/tmp/ccJZcrMe.o(.text+0x14): In function `main':
: 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> >&)'
/home/staszek/tmp/ccJZcrMe.o(.text+0x21): In function `main':
: undefined reference to `std::cout'
/home/staszek/tmp/ccJZcrMe.o(.text+0x26): In function `main':
: 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*)'
/home/staszek/tmp/ccJZcrMe.o(.text+0x2f): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/home/staszek/tmp/ccJZcrMe.o(.text+0x5c): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/home/staszek/tmp/ccJZcrMe.o(.text+0x8b): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/home/staszek/tmp/ccJZcrMe.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

I use Mandrake 10.0 and?... Well, I'd just like someone to answer.
 
Old 09-26-2004, 12:06 AM   #2
sether
Member
 
Registered: Aug 2004
Posts: 695

Rep: Reputation: 31
i think "g++" if it's a c++ program. you might also want to specify the file it will make with the "-o" option.
 
Old 09-26-2004, 12:33 AM   #3
lu543285
LQ Newbie
 
Registered: Jan 2004
Location: &#346;widnik
Distribution: Mandrake 10.0
Posts: 21

Original Poster
Rep: Reputation: 15
I've got it. That wasn't so difficult, was it?.
Now I'd like to link it and make it a runnable program.
Do I have to do it on my own or maybe there is a person who would be willing to give me some hints?.
 
Old 09-26-2004, 12:40 AM   #4
sether
Member
 
Registered: Aug 2004
Posts: 695

Rep: Reputation: 31
what do you mean? are you saying you want to only have to type "hello" at the commandline in any directory for it to work? like having it as an actual program on your computer?
 
Old 09-26-2004, 12:41 AM   #5
lu543285
LQ Newbie
 
Registered: Jan 2004
Location: &#346;widnik
Distribution: Mandrake 10.0
Posts: 21

Original Poster
Rep: Reputation: 15
Ay, Ay.
 
Old 09-26-2004, 12:45 AM   #6
lu543285
LQ Newbie
 
Registered: Jan 2004
Location: &#346;widnik
Distribution: Mandrake 10.0
Posts: 21

Original Poster
Rep: Reputation: 15
Yes, that's exactly what I want.
 
Old 09-26-2004, 01:00 AM   #7
lu543285
LQ Newbie
 
Registered: Jan 2004
Location: &#346;widnik
Distribution: Mandrake 10.0
Posts: 21

Original Poster
Rep: Reputation: 15
I've just went through g++ man and still cannot find it.
I think it must be some problem with linking.
 
Old 09-26-2004, 01:11 AM   #8
sether
Member
 
Registered: Aug 2004
Posts: 695

Rep: Reputation: 31
i think "link" or "symlink" will work with that, but you've gotta play around with it. i don't really know where you would link it to though (what directory).
 
Old 09-26-2004, 02:54 AM   #9
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
It should already be linked into an executable, but if you don't have . (current directory) in your path then you have to tell your shell where to find it. For example, try typing: ./hello
 
Old 09-26-2004, 03:35 AM   #10
lu543285
LQ Newbie
 
Registered: Jan 2004
Location: &#346;widnik
Distribution: Mandrake 10.0
Posts: 21

Original Poster
Rep: Reputation: 15
How to make my shell find the right directory with executable file in C++?.

I have compiled my hello.cpp program and I'd like to know where to find executable (if it's been created).
I have compiled it with 'g++ -o hello.cpp' command. I've got hello.o in my current directory but there's no
executable there. Where could I find executable?.
 
Old 09-26-2004, 03:38 AM   #11
sether
Member
 
Registered: Aug 2004
Posts: 695

Rep: Reputation: 31
you have to say the name you want after the -o, then the .cpp file. for example, if i wanted to compile hello.cpp and make an executable out of it called "hello", i would do this:

g++ -o hello hello.cpp

the newly created "hello" executable file will be in the same directory after the compile is through. execute it by typing

hello

and that's it.
 
Old 09-26-2004, 03:42 AM   #12
lu543285
LQ Newbie
 
Registered: Jan 2004
Location: &#346;widnik
Distribution: Mandrake 10.0
Posts: 21

Original Poster
Rep: Reputation: 15
Thanks

Thank you all for posting.
 
  


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
Various Compiling Errors (GCC compiling Openal, GUIlib, xmms-wma) gregorya Linux - Software 2 08-27-2004 05:03 AM
Errors compiling boombastic Linux - Newbie 7 08-04-2004 03:09 PM
Errors when compiling anything! adizzle Linux - Newbie 4 06-16-2004 05:27 PM
QT compiling errors slackwarefan Slackware 1 03-01-2004 07:45 PM
cryptic errors compiling simplest C program code_noc Slackware 4 10-06-2003 08:38 PM

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

All times are GMT -5. The time now is 08:20 AM.

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