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
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
01-22-2007, 03:11 AM
#1
Member
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 705
Rep:
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 .
01-22-2007, 03:22 AM
#2
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
"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.
01-22-2007, 03:44 AM
#3
Member
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 705
Original Poster
Rep:
Thanks, a stupid mistake wasted my time! I thought gcc can read all libraries...
01-22-2007, 04:02 AM
#4
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
gcc often is able to build C++ code, but doesn't know how to link the C++ runtime libraries
All times are GMT -5. The time now is 08:43 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News