[svlug] interesting and exotic linking error in .o files of cpp program

Karl Larsen k5di at zianet.com
Wed Nov 19 18:06:35 PST 2003


On Tue, 18 Nov 2003, Jonathan Su wrote:

> many people say if you are good at C, you can learn
> any language, as I was running a already tested c code
> and compiling it, an interesting and exotic linking
> error occurred, I am not certain whether this has to
> do with my red hat distribution, after analyzing the
> situation with abstract thoughts, I think it might be
> some compatibility issues with cout and cin with my
> particular library and compiler, it is just a guess.
> If anybody have any constructive criticism or
> comments, please let me know, thanks.

	I'm not good at any language, but found your problem rather 
easy. I copied your snippet to my Red Hat 9 as test.cc and discovered 
you had a { problem. I fixed that and it looks like this:


#include <iostream>
using namespace std;

int main()
{
   int i;
   double x;

   cout << "\nEnter a double; ";
   cin >> x;
   cout << "Enter a positive integer: ";
   cin >> i;
   while (i< 1) {
           cerr << "errpr i = " << i << endl;
           cout << "Enter a positive integer:  ";
           cin >> i;
	         }
}

and it compiles with g++ and the compiled exicutable works properly. If 
this function is supposed to do something then you need to return it. It 
might look like 

	return (x,i);

So be careful with your {} as they ARE important.



> 
> *************************actual
> program****************
> #include <iostream>
> using namespace std;
> 
> int main()
> {
>    int i;
>    double x;
> 
>    cout << "\nEnter a double; ";
>    cin >> x;
>    cout << "Enter a positive integer: ";
>    cin >> i;
>    while (i< 1) {
>            cerr << "errpr i = " << i << endl;
>            cout << "Enter a positive integer; ";
>            cin >> i;
>    };
>    cout << "i *x = " << i*x <<endl;
> }
> **************************output**********************
> [pacman at localhost C]$ gcc io.cpp
> /tmp/cc2KYP8A.o: In function `main':
> /tmp/cc2KYP8A.o(.text+0x19): undefined reference to
> `std::cout'
> /tmp/cc2KYP8A.o(.text+0x1e): 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/cc2KYP8A.o(.text+0x2d): undefined reference to
> `std::cin'
> /tmp/cc2KYP8A.o(.text+0x32): undefined reference to
> `std::basic_istream<char, std::char_traints<char>
> >::operator>>(double&)'
> /tmp/cc2KYP8A.o(.text+0x42): undefined reference to
> `std::cout'
> /tmp/cc2KYP8A.o(.text+0x47): 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/cc2KYP8A.o(.text+0x56): undefined reference to
> `std::cin'
> /tmp/cc2KYP8A.o(.text+0x5b): undefined reference to
> `std::basic_istream<char, std::char_traints<char>
> >::operator>>(int&)'
> /tmp/cc2KYP8A.o(.text+0x6e): 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/cc2KYP8A.o(.text+0x81): undefined reference to
> `std::cerr'
> /tmp/cc2KYP8A.o(.text+0x86): 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/cc2KYP8A.o(.text+0x8f): undefined reference to
> `std::basic_ostream<char, std::char_traits<char>
> >::operator<<(int)'
> /tmp/cc2KYP8A.o(.text+0x98): 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/cc2KYP8A.o(.text+0xa8): undefined reference to
> `std::cout'
> /tmp/cc2KYP8A.o(.text+0xad): 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/cc2KYP8A.o(.text+0xbc): undefined reference to
> `std::cin'
> /tmp/cc2KYP8A.o(.text+0xc1): undefined reference to
> `std::basic_istream<char, std::char_traints<char>
> >::operator>>(int&)'
> /tmp/cc2KYP8A.o(.text+0xce): 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/cc2KYP8A.o(.text+0xeb): undefined reference to
> `std::cout'
> /tmp/cc2KYP8A.o(.text+0xf0): 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/cc2KYP8A.o(.text+0xf9): undefined reference to
> `std::basic_ostream<char, std::char_traits<char>
> >::operator<<(double)'
> /tmp/cc2KYP8A.o(.text+0x102): 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/cc2KYP8A.o: In function
> `__static_initialization_and_destruction_0(int, int)':
> /tmp/cc2KYP8A.o(.text+0x12e): undefined reference to
> `std::ios_base::Init::Init[in-charge]()'
> /tmp/cc2KYP8A.o: In function `__tcf_0':
> /tmp/cc2KYP8A.o(.text+0x15d): undefined reference to
> `std::ios_base::Init::~Init [in-charge]()'
> /tmp/cc2KYP8A.o(.eh_frame+0x11): undefined reference
> to `__gxx_personality_v0'
> collect2: ld returned 1 exit status
> 
> 
> _______________________________________________
> svlug mailing list
> svlug at lists.svlug.org
> http://lists.svlug.org/lists/listinfo/svlug
> 

-- 
                      
               - Karl Larsen k5di Las Cruces,NM Az ScQRPions -





More information about the svlug mailing list