Archived

This forum has been archived. Please start a new discussion on GitHub.

problem with IceUtil::Monitor(link errors)

Hello,when i'm trying to use monitor object for wait-notify and locking.
I get some errors from the compiler.
any one can help me or give me some advice.
Thanks!

someting about ENV:
OS: WIN 2003
VS: VS 2005
Language: C++
ICE: Ice-3.0.1-VC80
link errors from VS2005:
Error 1 error LNK2005: "public: void __thiscall IceUtil::Monitor<class IceUtil::Mutex>::notify(void)" (?notify@?
@IceUtil@@QAEXXZ) already defined in
ControlManager.obj Ice.lib
Error 2 error LNK2005: "public: void __thiscall IceUtil::Monitor<class IceUtil::Mutex>::unlock(void)const " (?unlock@?
@IceUtil@@QBEXXZ) already defined in CardManager.obj Ice.lib
Error 3 error LNK2005: "public: void __thiscall IceUtil::Monitor<class IceUtil::Mutex>::lock(void)const " (?lock@?
@IceUtil@@QBEXXZ) already defined in CardManager.obj Ice.lib
Error 4 fatal error LNK1169: one or more multiply defined symbols

found D:\CallCenter\CallCenter\Release\CallCenter.exe

********************************************
files:
CardMananger.h
ControlManager.h
ThrQuque.h
ThrQuque.h is based on the sample code (page 695 Ice-3.0.1.pdf)
I add timeout wait to this sample.

//CardMananger.h
#include <IceUtil/Thread.h>
//
#include "ThrQueue.h"
........
//ControlManager.h
#include <IceUtil/Thread.h>
//
#include "ThrQueue.h"
//ThrQueue.h
// base on page 695 Ice-3.0.1.pdf
#ifndef _THR_QUEUE_H
#define _THR_QUEUE_H
#include <IceUtil/Monitor.h>
#include <IceUtil/Mutex.h>
#include <list>
using namespace std;
////
//MessageQueuq
////
template<class T> class ThrQueue: public IceUtil::Monitor<IceUtil::Mutex>
{
public:
ThrQueue() : _waitingReaders(0) {}
void put(const T & item) {
IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
_q.push_back(item);
if (_waitingReaders)
notify();
}
bool get(T & item) {
IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
while (_q.size() == 0) {
try {
++_waitingReaders;
wait();
--_waitingReaders;
} catch (...) {
--_waitingReaders;
return false;
}
}
item = _q.front();
_q.pop_front();
return true;
}
bool get(T & item,const IceUtil::Time &t) {
IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
while (_q.size() == 0) {
try {
++_waitingReaders;
if(!timedWait(t)){
return false;
};
--_waitingReaders;
} catch (const IceUtil::ThreadLockedException &) {
--_waitingReaders;
return false;
}
}
item = _q.front();
_q.pop_front();
return true;
}
private:
list<T> _q;
short _waitingReaders;
};
#endif

Comments

  • Please update your signature as described in this post.

    Cheers,

    Michi.
  • I'm so sorry!

    I'm so sorry!
    I have updated my signature.

    some new Clues :
    when I change this code
    void put(const T & item) {
    IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
    _q.push_back(item);
    if (_waitingReaders)
    notify();
    }
    To
    void put(const T & item) {
    //IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
    //_q.push_back(item);
    //if (_waitingReaders)
    //notify();

    }
    everything is Ok.
  • benoit
    benoit Rennes, France
    Hi,

    It's difficult to say what could be the reason for this link error without seeing the Visual Studio project you're using to build your application. Could you send us a small self contained example demonstrating the error?

    Cheers,
    Benoit.
  • I copied and pasted your code in the thread test client in test/IceUtil/thread, and it compiled and linked fine.

    From the error message, you are getting duplicate symbols. My guess is that, possibly, the Lock template is instantiated more than once. I'd check the build settings of your project and compare to one of the demo or test projects in the source distribution. Most likely, the culprit is there somewhere.

    Cheers,

    Michi.
  • solution

    I got this error too.
    My solution is:
    create new header file, example "typedef.h".
    on this file, include all ICE header you need.
    example:
    #ifndef __TYPEDEF_H__
    #define __TYPEDEF_H__

    #include <Ice/Ice.h>
    #include <IceUtil/Monitor.h>
    typedef IceUtil::Monitor<IceUtil::Mutex> TMonitor;

    #endif


    NODE:
    donn't include <Ice/Ice.h> on .cpp file. it must include on .h file.
    why? I donn't hnow?:confused: