Amela

Hi!

I'm migrating code from Visual Studio 2003 to Visual Studio 2005 and have run into problems with a rather simple piece of code that compiles and links fine in 2003 but fails to link in 2005.

Basically, I have a deque class that contains pointers to objects of a simple class. I defined a sorting predicate function and try to sort the queue.

Here's the essence of what I'm trying to do - I've stripped the code down to bare bones:

Code Block

class TestDeque

{

};

static bool ComparisonFunction( const TestDeque *e1, const TestDeque *e2)

{

return true;

}

std::deque<TestDeque *> MyQueue;

std::sort(MyQueue.begin(), MyQueue.end(), ComparisonFunction);

This results with the following link error:

PMAN_ServicePool.obj : error LNK2019: unresolved external symbol "bool __cdecl o
perator<<class std::_Deque_iterator<class TestDeque *,class std::allocator<class
TestDeque *>,0> >(class std::_Deque_iterator<class TestDeque *,class std::alloc
ator<class TestDeque *>,0> const &,class std::_Deque_iterator<class TestDeque *,
class std::allocator<class TestDeque *>,0> const &)" ( $ MV $_Deque_iterator@PA
VTestDeque@@V $allocator@PAVTestDeque@@@std@@$0A@@std@@@@YA_NABV $_Deque_iterato
r@PAVTestDeque@@V $allocator@PAVTestDeque@@@std@@$0A@@std@@0@Z) referenced in fu
nction "struct std:Stick out tongueair<class std::_Deque_iterator<class TestDeque *,class std:
:allocator<class TestDeque *>,0>,class std::_Deque_iterator<class TestDeque *,cl
*** std::allocator<class TestDeque *>,0> > __cdecl std::_Unguarded_partition<cla
ss std::_Deque_iterator<class TestDeque *,class std::allocator<class TestDeque *
>,0>,bool (__cdecl*)(class TestDeque const *,class TestDeque const *)>(class std
::_Deque_iterator<class TestDeque *,class std::allocator<class TestDeque *>,0>,c
lass std::_Deque_iterator<class TestDeque *,class std::allocator<class TestDeque
*>,0>,bool (__cdecl*)(class TestDeque const *,class TestDeque const *))" ( $_U
nguarded_partition@V $_Deque_iterator@PAVTestDeque@@V $allocator@PAVTestDeque@@@
std@@$0A@@std@@P6A_NPBVTestDeque@@0@Z@std@@YA AU $pair@V $_Deque_iterator@PAVTes
tDeque@@V $allocator@PAVTestDeque@@@std@@$0A@@std@@V12@@0@V $_Deque_iterator@PAV
TestDeque@@V $allocator@PAVTestDeque@@@std@@$0A@@0@0P6A_NPBVTestDeque@@1@Z@Z)

If I change MyQueue to be

Code Block

std::deque<TestDeque> MyQueue;

everything's fine.

The code above seems perfectly valid to me. What am I missing here

Can anyone help This is quite easy to reproduce.

Thanks!



Re: Visual C++ Language error LNK2019: unresolved external symbol - when trying to sort an std::deque

Bruno van Dooren

It compiles fin with VC2005 SP1 on my computer

#include "stdafx.h"

#include <deque>

#include <algorithm>

using namespace std;

class TestDeque

{

};

static bool ComparisonFunction( const TestDeque *e1, const TestDeque *e2)

{

return true;

}

std:Big Smileeque<TestDeque*> MyQueue;

int _tmain(int argc, _TCHAR* argv[])

{

std:Tongue Tiedort(MyQueue.begin(), MyQueue.end(), ComparisonFunction);

return 0;

}

when converting to VC2005, did you do a clean and then a full rebuild

There has to be some other problem.





Re: Visual C++ Language error LNK2019: unresolved external symbol - when trying to sort an std::deque

Amela

Hi Bruno,

You were right, there _was_ some other problem - one of the header files that were being included had a template declaration for a "<" operator like this:

template <class KeyType>
bool
operator <(const KeyType &lhs, const KeyType &rhs);

This was a left-over from a long time ago when it was actually needed, now it's no longer used anywhere in our code.

However, it seems in VC8 this triggered something in the std:Tongue Tiedort to look for the implementation for this operator.

I removed this declaration and it is now linking successfully, so I'm over this hurdle Smile

But I still don't understand why it would be looking for the "<" operator when I'm specifying the comparison function ...