undefined reference to

The following are the errors

xx/trustmanager.o: In function `TrustManager::updateTrust(int, double, double)':
trustmanager.cc:(.text+0xde): undefined reference to `Rating::updateRating(double, double, double, double)'
xx/trustmanager.o: In function `TrustManager::handleInactivityTimeout()':
trustmanager.cc:(.text+0x241): undefined reference to `Rating::updateRating(double, double, double, double)'
xx/trustmanager.o: In function `TrustManager::initNewRating(double, double, double)':
trustmanager.cc:(.text+0x306): undefined reference to `Rating::updateRating(double, double, double, double)'
xx/monitor.o: In function `Monitor::handlePacketSent(Packet*)':
monitor.cc:(.text+0x359): undefined reference to `PackData::PackData(Packet*, double)'
xx/reputationsystem.o: In function `ReputationSystem::handleFirstHandInfo(int&, Behavior)':
reputationsystem.cc:(.text+0x2a5): undefined reference to `Rating::updateRating(double, double, double, double)'
xx/reputationsystem.o: In function `ReputationSystem::initNewRating(double, double, double)':
reputationsystem.cc:(.text+0x548): undefined reference to `Rating::updateRating(double, double, double, double)'
xx/reputationsystem.o: In function `ReputationSystem::updateReputation(int, double, double, double, double)':
reputationsystem.cc:(.text+0x653): undefined reference to `Rating::updateRating(double, double, double, double)'
xx/reputationsystem.o: In function `ReputationSystem::handleInactivityTimeout()':
reputationsystem.cc:(.text+0x734): undefined reference to `Rating::updateRating(double, double, double, double)'
reputationsystem.cc:(.text+0x821): undefined reference to `Rating::updateRating(double, double, double, double)'
collect2: ld returned 1 exit status
make: *** [ns] Error 1




The code is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//K.4 Reputationsystem.h
#ifndef _reputation_system
#define _reputation_system
class ReputationSystem;
class DSRAgent;
class InactivityTimer : public TimerHandler {
public:
InactivityTimer(ReputationSystem *a) : TimerHandler() { a_ = a;}
void expire(Event *e);
protected:
ReputationSystem *a_;
};
class PublishingTimer : public TimerHandler {
public:
PublishingTimer(ReputationSystem *a) : TimerHandler() { a_ = a;}
void expire(Event *e);
protected:
ReputationSystem *a_;
};
class ReputationSystem
{
public:
/****** functions ******/
ReputationSystem(DSRAgent* agent);
//constructor
void handleFirstHandInfo(nsaddr_t& address, Behavior behavior);
//Handle firsthand oberserved information
void handleSecondHandInfo(nsaddr_t from, nsaddr_t address, double alpha, double beta);
//Handle secondhand information published by neighbor node
void setPathManager(RouteCache* pathmanager);
void setNetID(nsaddr_t address);
void Terminate();
private:
/****** functions ******/
void handlePublishingTimeout();
void handleInactivityTimeout();
Rating* initNewRating(double alpha, double beta, double fading);
void updateReputation(nsaddr_t address, double alpha, double beta, double fading, double weight);
bool deviationTest(nsaddr_t address, double alpha1, double beta1, double alpha2, double beta2);
bool isMisbehavedNode(nsaddr_t address);
double BayeMean(double alpha, double beta);
/****** variables ******/
DSRAgent* dsragent;
RouteCache* path_manager;
TrustManager trust_manager;
map<nsaddr_t, Rating*> firsthandinfo_t;
RatingTable reputation_t;
InactivityTimer* inactivity_timer;
PublishingTimer* publishing_timer;
friend class InactivityTimer;
friend class PublishingTimer;
nsaddr_t net_id;
};
#endif 





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//K.5 Reputationsystem.cc
#include "reputationsystem.h"
ofstream reputationlog("reputationlog.txt");
void InactivityTimer::expire(Event * e)
{
a_->handleInactivityTimeout();
resched(INACTIVITY_TIMEOUT + INACTIVITY_TIMEOUT * Random::uniform(1.0));
}
void PublishingTimer::expire(Event * e)
{
a_->handlePublishingTimeout();
resched(PUBLISHING_TIMEOUT + PUBLISHING_TIMEOUT * Random::uniform(1.0));
}
/****************************************************
**** Public functions of ReputationSystem class ****
****************************************************/
ReputationSystem::ReputationSystem(DSRAgent* agent)
{
this->dsragent = agent;
this->inactivity_timer = new InactivityTimer(this);
inactivity_timer->sched(INACTIVITY_TIMEOUT + INACTIVITY_TIMEOUT * Random::uniform(1.0));
this->publishing_timer = new PublishingTimer(this);
publishing_timer->sched(PUBLISHING_TIMEOUT + PUBLISHING_TIMEOUT * Random::uniform(1.0));
}

void ReputationSystem::handleSecondHandInfo(nsaddr_t from, nsaddr_t address, double alpha1, double beta1)
{
map<nsaddr_t, Rating*>::iterator it;
it = reputation_t.find(address);
if (it == reputation_t.end())
{
reputation_t[address] = new Rating(1.0, 1.0);
}
double alpha2 = reputation_t[address]->getAlpha();
double beta2 = reputation_t[address]->getBeta();
bool isPass = deviationTest(address, alpha1, beta1, alpha2, beta2);
if ( ((USING_TRUST == 1) && isPass) || ((USING_TRUST == 1) && trust_manager.isTrustworthy(from)))
{
if(CONFIDANTDEBUG)
{
reputationlog << "Node " << net_id << " handle secondhand info from ";
reputationlog << from << ":" << address << " [" << alpha1 << "," << beta1 << "] ";
reputationlog << " [" << alpha2 << "," << beta2 << "] " << endl;
}
updateReputation(address, alpha1, beta1, 1, SECONDHAND_INFO_WEIGHT);
}
double alpha = isPass ? 0 : 1;
trust_manager.updateTrust(address, alpha, 1-alpha);
return;
}
void ReputationSystem::setNetID(nsaddr_t address)
{
net_id = address;
}
void ReputationSystem::setPathManager(RouteCache* pathmanager)
{
this->path_manager = pathmanager;
}
/*void ReputationSystem::Terminate()
{
map<nsaddr_t, Rating*>::iterator it;
for (it = reputation_t.begin(); it != reputation_t.end(); it ++)
{
reputationlog << "_" <<net_id << "_ Reputation values [" << it->first << ", alpha:";
reputationlog << it->second->getAlpha() << ", beta:" << it->second->getBeta() << "] ";
reputationlog << "mean: " << BayeMean(it->second->getAlpha(), it->second->getBeta()) << endl;
}
path_manager->Terminate(net_id);
}*/
/*****************************************************
**** Private functions of ReputationSystem class ****
*****************************************************/
Rating* ReputationSystem::initNewRating(double alpha, double beta, double fading)
{
Rating* rating = new Rating(1.0, 1.0);
rating->updateRating(alpha, beta, fading, 1);
return rating;
}
void ReputationSystem::updateReputation(nsaddr_t address, double alpha, double beta, double fading, double weight)
{
map<nsaddr_t, Rating*>::iterator it;
it = reputation_t.find(address);
if (it == reputation_t.end())
{
reputation_t[address] = initNewRating(alpha, beta, 1);
}
else
{
if (CONFIDANTDEBUG)
{
reputationlog << "Before updating: ";
reputationlog << "_" << net_id <<"_ node "<<address <<": [";
reputationlog << (it->second)->getAlpha() <<","<<(it->second)->getBeta()<<"]"<<endl;
}
(it->second)->updateRating(alpha, beta, fading, weight);
}
it = reputation_t.find(address);
if (CONFIDANTDEBUG)
{
reputationlog << "After updating: ";
reputationlog << "_" << net_id <<"_ node "<<address <<" reputation updated: [";
reputationlog << (it->second)->getAlpha() <<","<<(it->second)->getBeta()<<"]"<<endl;
}
if (isMisbehavedNode(address))
{
if (CONFIDANTDEBUG)
reputationlog << "Node " << address << " is put into _" << net_id << "_ misbehaved list" << endl;
//path_manager->addMisbehavedNode(address);
}
else
{
//path_manager->removeMisbehavedNode(address);
}
return;
}
void ReputationSystem::handleInactivityTimeout()
{
map<nsaddr_t, Rating*>::iterator it;
for (it = firsthandinfo_t.begin(); it != firsthandinfo_t.end(); it ++)
{
if ( (Scheduler::instance().clock() - (it->second)->getTime()) > INACTIVITY_TIMEOUT)
(it->second)->updateRating(0, 0, INACTIVITY_FADING, 1);
}
map<nsaddr_t, Rating*>::iterator it2;
for (it2 = reputation_t.begin(); it2 != reputation_t.end(); it2 ++)
{
if ( (Scheduler::instance().clock() - (it2->second)->getTime()) > INACTIVITY_TIMEOUT)
(it2->second)->updateRating(0, 0, INACTIVITY_FADING, 1);
}
trust_manager.handleInactivityTimeout();
}
void ReputationSystem::handlePublishingTimeout()
{
if (firsthandinfo_t.empty())
return;
if(CONFIDANTDEBUG)
{
map<nsaddr_t, Rating*>::iterator it;
it = firsthandinfo_t.begin();
reputationlog << "Node " << net_id << " at ";
reputationlog << Scheduler::instance().clock() << "publish time out ";
while (it != firsthandinfo_t.end())
{
double alpha = (it->second)->getAlpha();
double beta = (it->second)->getBeta();
reputationlog << "[" << it->first << ": " << alpha << "," << beta <<"]"; 
it ++;
}
reputationlog << endl;
}
dsragent->publishInfo(firsthandinfo_t);
}

}
<nolyc> Undefined reference is a linker error.
It's not a compile error. #includes don't help.
You did not define the thing in the error message, you forgot to link the file that defines it, you forgot to link to the library that defines it, or, if it's a static library, you have the wrong order on the linker command line.
Check which one. (Note that some linkers call it an unresolved external)


Also
indentation
<nolyc> indentation is optional whitespace. see also: !vowel
vowel
<nolyc> vwls r bt s sfl s whtspc, spclly n vrbl nms. s ls: !ndnttn
ndnttn
<nolyc> indentation is optional whitespace. see also: !vowel
Topic archived. No new replies allowed.