473,385 Members | 1,901 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,385 software developers and data experts.

N00b looking for GCC error help.

Hello all ... here is my problem. I just got the book "Teach Yourself C
++ in 21 Days"

Setup:
Fedora Core 6 - i386
GCC 4.1.1

Again, I am a complete newcomer to C++, and this is one of the first
examples out of the book. I want to know why exactly this doesn't
clean compile, and how would i fix it?
################################################## ###################
#include <iostream>

int Add (int x, int y)
{
std::cout << "In Add(), recieved " << x << " and " << y << "\n";
return (x+y);
}

int main()
{
using std::cout;
using std::cin;

cout << "I'm in main()!\n";
int a, b, c;

cout << "Enter two nunber: ";
cin >a;
cin >b;

cout << "\nCalling Add()\n";
c=Add(a,b);
cout << "\nBack in main().\n";
cout << "c was set to " << c;
cout << "\nExiting ... \n\n";

return 0;
}
################################################## #########


$ gcc ./Func.cpp -o Func

/tmp/cc3B71PJ.o: In function
`__static_initialization_and_destruction_0(int, int)':
Func.cpp:(.text+0x23): undefined reference to
`std::ios_base::Init::Init()'
/tmp/cc3B71PJ.o: In function `__tcf_0':
Func.cpp:(.text+0x6c): undefined reference to
`std::ios_base::Init::~Init()'
/tmp/cc3B71PJ.o: In function `Add(int, int)':
Func.cpp:(.text+0x83): undefined reference to `std::cout'
Func.cpp:(.text+0x88): 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*)'
Func.cpp:(.text+0x99): undefined reference to
`std::basic_ostream<char, std::char_traits<char::operator<<(int)'
Func.cpp:(.text+0xa9): 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*)'
Func.cpp:(.text+0xba): undefined reference to
`std::basic_ostream<char, std::char_traits<char::operator<<(int)'
Func.cpp:(.text+0xca): 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/cc3B71PJ.o: In function `main':
Func.cpp:(.text+0xf2): undefined reference to `std::cout'
Func.cpp:(.text+0xf7): 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*)'
Func.cpp:(.text+0x106): undefined reference to `std::cout'
Func.cpp:(.text+0x10b): 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*)'
Func.cpp:(.text+0x119): undefined reference to `std::cin'
Func.cpp:(.text+0x11e): undefined reference to
`std::basic_istream<char, std::char_traits<char::operator>>(int&)'
Func.cpp:(.text+0x12c): undefined reference to `std::cin'
Func.cpp:(.text+0x131): undefined reference to
`std::basic_istream<char, std::char_traits<char::operator>>(int&)'
Func.cpp:(.text+0x140): undefined reference to `std::cout'
Func.cpp:(.text+0x145): 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*)'
Func.cpp:(.text+0x169): undefined reference to `std::cout'
Func.cpp:(.text+0x16e): 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*)'
Func.cpp:(.text+0x17d): undefined reference to `std::cout'
Func.cpp:(.text+0x182): 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*)'
Func.cpp:(.text+0x193): undefined reference to
`std::basic_ostream<char, std::char_traits<char::operator<<(int)'
Func.cpp:(.text+0x1a2): undefined reference to `std::cout'
Func.cpp:(.text+0x1a7): 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/cc3B71PJ.o:(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status

Feb 28 '07 #1
4 2201
su**********@gmail.com wrote:
>
Again, I am a complete newcomer to C++, and this is one of the first
examples out of the book. I want to know why exactly this doesn't
clean compile, and how would i fix it?
$ gcc ./Func.cpp -o Func
g++ ./Func.cpp -o Func

--
Ian Collins.
Feb 28 '07 #2
On 28 fev, 17:02, sublimani...@gmail.com wrote:
Hello all ... here is my problem. I just got the book "Teach Yourself C
++ in 21 Days"
[snip]

You should be using "Accelerated C++" or "You Can Do It" to start in C+
+.
>
Setup:
Fedora Core 6 - i386
GCC 4.1.1

Again, I am a complete newcomer to C++, and this is one of the first
examples out of the book. I want to know why exactly this doesn't
clean compile, and how would i fix it?

[snip]
$ gcc ./Func.cpp -o Func
This is off-topic here, but try:

$ g++ ./Func.cpp -o Func

The problem seems you didn't link the STL code.

HTH,

Marcelo Pinto

Feb 28 '07 #3
su**********@gmail.com wrote:
Hello all ... here is my problem. I just got the book "Teach Yourself
C ++ in 21 Days"

Setup:
Fedora Core 6 - i386
GCC 4.1.1

Again, I am a complete newcomer to C++, and this is one of the first
examples out of the book. I want to know why exactly this doesn't
clean compile, and how would i fix it?
################################################## ###################
[..]
################################################## #########


$ gcc ./Func.cpp -o Func

/tmp/cc3B71PJ.o: In function
`__static_initialization_and_destruction_0(int, int)':
Func.cpp:(.text+0x23): undefined reference to
`std::ios_base::Init::Init()'
[..]
collect2: ld returned 1 exit status
Whenever you have linker errors ('ld' is the linker), you need to
make sure you're supplying all the necessary modules to it. How?
That's an implementation-specific question. Try gnu.g++.help NG.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 28 '07 #4
Wow .... i feel like an idiot.

"g++" did the trick.

Thanks for the help, everybody.

Feb 28 '07 #5

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

Similar topics

4
by: turnstyle | last post by:
Hey all, sorry for asking such a grunt question, and thanks in advance for any help... My hosting ISP offers access to their MS-SQL database, and my understanding is that it's generally simplest...
5
by: Peter Ong | last post by:
Hello, I'm very new to C. I have followed some of the earlier programs in the K&R book, but I am still far from even being a novice. For a long time I was looking for a little support group...
1
by: newgenre | last post by:
I am using a pre-built package of code for my site, which is called EasyDisc. All it does is it creates an interactive forum on your site, like any forum you see anywhere. I am having a problem...
1
by: CosmicLogick | last post by:
This following piece of code wont work, i have no idea what i did wrong. Data.mdb is the database file Admin is the table username and password are fields oldpasstxt.Text and newpasstxt.Text...
7
by: Alan | last post by:
When you use a function like I see posted here often, like: Public Function Whatever() stuff... End Function What do you actually do with that to make it run? I assumed you put it in a...
4
by: onefry | last post by:
Hey I have this prog that i'm working on, starting my first c++ class and kind of a n00b to programming here it is #include <iostream> #include <cstdlib> using namespace std;
6
by: Charles | last post by:
I am learning from the Accelerated C++ book. The following example doesn't work and I don't know why: #include <iostream> #include <string> int main () { const std::string exclam = "!"; const...
8
by: HardHackz | last post by:
Hey, I'm trying to learn C++, the problem is, when I do cout << "Hello World!"; it always opens dos and closes it to quickly to see...i know im a total n00b, but any help?
0
by: hockeyjk | last post by:
All, I'm writing a program that creates a histogram of data. IDLE is freezing up after the window opens (doesn't prompt user or graph anything). The window that opens is named "tk" rather than...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.