Thread: using std::find linking fail in linux

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    2

    using std::find linking fail in linux

    I am trying to experiment <algorithm>'s find to search for an item in a
    vector of struct. My bit of test code is shown below.

    Code:
    #include <algorithm>
    #include <iterator>
    #include <functional>
    
    bool operator==( const ClsInstBk& rhs, const ClsInstBk& lhs );
    
    class	ClsInstBkTable
    {
    public:
    	ClsInstBkTable();
    	UINT32 Add( const ClsInstBk& breakpoint );	// Add a breakpoint
    	UINT32 Remove( const ClsInstBk& breakpoint ); // Remove a breakpoint
    	bool IsBreak( UINT32 ulPC );	//check if the specified PC is breakpoint or not
    	UINT32 ClearAll();		//clear all breakpoints
    	bool IsBreakInstruction( TypMemoryData ulValue );
    	int Find( UINT32 ulPC );//return -1 if ulPC is not set  breakpoint, else return index of pool
    	TypMemoryData GetOriginalMemoryValue( int index );
    	UINT32 EnableBreak( UINT32 index );
    	int DisableBreak( UINT32 index );
    	static TypMemoryData BreakInstruction;
    private:
    	vector<ClsInstBk>	_vecBkTable;
    };
    
    ......
    
    UINT32 ClsInstBkTable::Add( const ClsInstBk& temp )
    {
    	//if breakpoint is not in table, add it; 
    	//std::vector<ClsInstBk>::iterator i = std::find( _vecBkTable.begin(), _vecBkTable.end(), temp );
    	std::vector<ClsInstBk>::iterator i;
    	i = std::find( _vecBkTable.begin(), _vecBkTable.end(), temp );
    	if( _vecBkTable.end() == i )
    	{
    		_vecBkTable.push_back( temp );
    	}
    	return 0;
    }
    The compile is ok. But the link is fail and errors as following.

    Code:
    g++ -g -Wno-deprecated -DGEN_MIF -DNO_DPI -I/localhome/tools/systemc-2.2.0/include -I/home/tools/NC_Verilog/IUS6.2/linux/tools/include/ -I. -I./../../include ./breakpoint.o ./eDSP_decode_grab.o ./eDSP_decode.o ./eDSP_cmd.o ./eDSP_disasmoneinst.o ./eDSP_grab.o ./eDSP_hardware.o ./eDSP_misc.o ./main.o  -L/localhome/tools/systemc-2.2.0/lib-linux -L/usr/lib -lm -lsystemc -lpthread -o eDSP
    ./breakpoint.o(.gnu.linkonce.t._ZSt4findIN9__gnu_cxx17__normal_iteratorIP9ClsInstBkSt6vectorIS2_SaIS2_EEEES2_ET_S8_S8_RKT0_St26random_access_iterator_tag+0x3d): In function `__gnu_cxx::__normal_iterator<ClsInstBk*, std::vector<ClsInstBk, std::allocator<ClsInstBk> > > std::find<__gnu_cxx::__normal_iterator<ClsInstBk*, std::vector<ClsInstBk, std::allocator<ClsInstBk> > >, ClsInstBk>(__gnu_cxx::__normal_iterator<ClsInstBk*, std::vector<ClsInstBk, std::allocator<ClsInstBk> > >, __gnu_cxx::__normal_iterator<ClsInstBk*, std::vector<ClsInstBk, std::allocator<ClsInstBk> > >, ClsInstBk const&, std::random_access_iterator_tag)':
    /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h:207: undefined reference to `operator==(ClsInstBk const&, ClsInstBk const&)'
    ./breakpoint.o(.gnu.linkonce.t._ZSt4findIN9__gnu_cxx17__normal_iteratorIP9ClsInstBkSt6vectorIS2_SaIS2_EEEES2_ET_S8_S8_RKT0_St26random_access_iterator_tag+0x78):/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h:211: undefined reference to `operator==(ClsInstBk const&, ClsInstBk const&)'
    
    ./breakpoint.o(.gnu.linkonce.t._ZSt4findIN9__gnu_cxx17__normal_iteratorIP9ClsInstBkSt6vectorIS2_SaIS2_EEEES2_ET_S8_S8_RKT0_St26random_access_iterator_tag+0xb3):/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h:215: undefined reference to `operator==(ClsInstBk const&, ClsInstBk const&)'
    
    ./breakpoint.o(.gnu.linkonce.t._ZSt4findIN9__gnu_cxx17__normal_iteratorIP9ClsInstBkSt6vectorIS2_SaIS2_EEEES2_ET_S8_S8_RKT0_St26random_access_iterator_tag+0xee):/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h:219: undefined reference to `operator==(ClsInstBk const&, ClsInstBk const&)'
    
    ./breakpoint.o(.gnu.linkonce.t._ZSt4findIN9__gnu_cxx17__normal_iteratorIP9ClsInstBkSt6vectorIS2_SaIS2_EEEES2_ET_S8_S8_RKT0_St26random_access_iterator_tag+0x16f):/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h:227: undefined reference to `operator==(ClsInstBk const&, ClsInstBk const&)'
    
    ./breakpoint.o(.gnu.linkonce.t._ZSt4findIN9__gnu_cxx17__normal_iteratorIP9ClsInstBkSt6vectorIS2_SaIS2_EEEES2_ET_S8_S8_RKT0_St26random_access_iterator_tag+0x1aa):/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h:231: more undefined references to `operator==(ClsInstBk const&, ClsInstBk const&)' follow
    collect2: ld returned 1 exit status
    I don't fully understand what the error message is trying to say.

    Any comments appreciated.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    The error message seems to be saying that the linker cannot find the implementation of this

    Code:
    bool operator==( const ClsInstBk& rhs, const ClsInstBk& lhs );
    Either you don't have the implementation, or you are not compiling and linking it.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    2
    Quote Originally Posted by anon View Post
    The error message seems to be saying that the linker cannot find the implementation of this

    Code:
    bool operator==( const ClsInstBk& rhs, const ClsInstBk& lhs );
    Either you don't have the implementation, or you are not compiling and linking it.

    Thank you. Yes, it does. After adding the implementation of operator==, it's ok.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Back from the depths of Linux
    By SpEcIeS in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 03-03-2005, 12:09 PM
  2. Linux
    By cerin in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 02-10-2005, 09:41 PM
  3. installing linux for the first time
    By Micko in forum Tech Board
    Replies: 9
    Last Post: 12-06-2004, 05:15 AM
  4. Linux for Windows!
    By Strut in forum Linux Programming
    Replies: 2
    Last Post: 12-25-2002, 11:36 AM
  5. Linux? Windows Xp?
    By VooDoo in forum Linux Programming
    Replies: 15
    Last Post: 07-31-2002, 08:18 AM