LinuxQuestions.org
Visit Jeremy's Blog.
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 01-22-2007, 03:11 AM   #1
kpachopoulos
Member
 
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 705

Rep: Reputation: 30
c++ linker errors


Hi,
here's the program:

Code:
string decToBin(int num)
{
	string s;
	int remainder=0;
	
	while (true)
	{
		if (num==0)
		{
			break;
		}
	
		remainder=num%2;
		s=i2str(remainder)+s;
		num=num >> 1;
	}
	
	return s;
}

string i2str(int aV)
{
	char buf[8];
	sprintf(buf, "%d", aV);
	return (string)buf;
}
and here are the errors. I have no idea what they are about (OK i understand they have to do with allocating a string, but...):
Code:
test4.cpp:46:2: warning: no newline at end of file
test4.cpp: In function ‘int main()’:
test4.cpp:45: warning: cannot pass objects of non-POD type ‘struct std::string’ through ‘...’; call will abort at runtime
/tmp/ccYbXerR.o: In function `__static_initialization_and_destruction_0(int, int)':
test4.cpp:(.text+0x23): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccYbXerR.o: In function `__tcf_0':
test4.cpp:(.text+0x66): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccYbXerR.o: In function `i2str(int)':
test4.cpp:(.text+0xa1): undefined reference to `std::allocator<char>::allocator()'
test4.cpp:(.text+0xb1): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
test4.cpp:(.text+0xba): undefined reference to `std::allocator<char>::~allocator()'
test4.cpp:(.text+0xcd): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccYbXerR.o: In function `decToBin(int)':
test4.cpp:(.text+0xff): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
test4.cpp:(.text+0x15a): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
test4.cpp:(.text+0x163): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
test4.cpp:(.text+0x176): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
test4.cpp:(.text+0x185): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
test4.cpp:(.text+0x198): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
test4.cpp:(.text+0x1b7): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccYbXerR.o: In function `std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
test4.cpp:(.text._ZStplIcSt11char_traitsIcESaIcEESbIT_T0_T1_ERKS6_S8_[std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x1e): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
test4.cpp:(.text._ZStplIcSt11char_traitsIcESaIcEESbIT_T0_T1_ERKS6_S8_[std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x2b): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::append(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
test4.cpp:(.text._ZStplIcSt11char_traitsIcESaIcEESbIT_T0_T1_ERKS6_S8_[std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x3e): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccYbXerR.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

Last edited by kpachopoulos; 01-22-2007 at 03:12 AM.
 
Old 01-22-2007, 03:22 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
"undefined reference" means the linker can not find all the libraries (e.g. libstdc++). Which compiler are you using, anyway? For C++ code better to use g++, not gcc.
 
Old 01-22-2007, 03:44 AM   #3
kpachopoulos
Member
 
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 705

Original Poster
Rep: Reputation: 30
Thanks, a stupid mistake wasted my time! I thought gcc can read all libraries...
 
Old 01-22-2007, 04:02 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
gcc often is able to build C++ code, but doesn't know how to link the C++ runtime libraries
 
  


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
Linker errors with Kylix3 C++ on Mandrake 9.1 HVDV Programming 10 08-30-2006 11:12 PM
ld linker errors Ankit mittal Programming 1 09-30-2005 03:05 PM
linker errors -please help MarcReing Programming 1 07-20-2005 07:44 AM
C++ - class template - linker errors? Wynd Programming 2 10-19-2004 03:54 PM
Linker errors daveyboy685 Linux - Software 1 03-25-2004 12:25 PM

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

All times are GMT -5. The time now is 08:43 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