C++ 中的意外 LNK 2019 class
Unexpected LNK 2019 in C++ class
我在尝试构建项目时遇到以下链接器问题。
我浏览了这里的其他帖子,据我所知,我使用的唯一外部组件是标准成员(并用 std:: 标识)或原语。有什么明显的东西是我在这里遗漏的吗?
使用 Eclipse C++ (Mars) 在 Win 7 Professional 64bit 上使用内部 eclipse builder 构建。
日志:
link /debug /nologo /OUT:SAD-Snoop.exe "src\ByteScanner.obj" "src\EncType.obj" "src\SAD-Snoop.obj" "src\SearchHits.obj"
SearchHits.obj : error LNK2019: unresolved external symbol "public: long __thiscall SearchHits::GetHitAddress(unsigned int)" (GetHitAddress@SearchHits@@QAEJI@Z) referenced in function "public: bool __thiscall SearchHits::Merge(class SearchHits)" (?Merge@SearchHits@@QAE_NV1@@Z)
SAD-Snoop.exe : fatal error LNK1120: 1 unresolved externals
14:28:44 Build Finished (took 909ms)
Header:
/*
* SearchHits.h
*
* Created on: 30 Jun 2015
* Author: Nick Boyd
*/
#ifndef SEARCHHITS_H_
#define SEARCHHITS_H_
#include <iostream>
#include <string>
#include <vector>
class SearchHits {
public:
SearchHits();
~SearchHits();
bool AddHit(std::string content, long address);
unsigned int CountHits();
std::string GetHit(unsigned int hitNumber);
long GetHitAddress(unsigned int hitNumber);
bool Merge(SearchHits hits);
private:
std::vector<std::string> hits;
std::vector<long> hitAddresses;
};
#endif /* SEARCHHITS_H_ */
class:
/*
* SearchHits.cpp
*
* Created on: 30 Jun 2015
* Author: Nick Boyd
*/
#include "SearchHits.h"
#include <string>
#include <iostream>
#include <vector>
std::vector<std::string> hitContents;
std::vector<long> hitAddresses;
SearchHits::SearchHits() {
}
SearchHits::~SearchHits() {
hitContents.clear();
hitAddresses.clear();
}
bool SearchHits::AddHit(std::string hitContent, long address) {
hitContents.push_back(hitContent);
hitAddresses.push_back(address);
return ((hitContents.back() == hitContent)
&& (hitAddresses.back() == address));
}
unsigned int SearchHits::CountHits() {
return hitContents.size();
}
std::string SearchHits::GetHit(unsigned int hitNumber) {
if (hitNumber < hitContents.size()) {
return hitContents[hitNumber];
} else {
std::cout << "Error in Function [SearchHits::GetHit()]" << std::endl
<< "Parameter [hitNumber] out of bounds: "
<< hitNumber + " Upper Limit: " << hitContents.size()
<< std::endl;
throw new std::invalid_argument(
"Error in Function [SearchHits::GetHit()] Parameter [hitNumber] out of bounds: "
+ std::to_string(hitNumber));
}
}
long GetHitAddress(unsigned int hitNumber) {
if (hitNumber < hitContents.size()) {
return hitAddresses[hitNumber];
} else {
std::cout << "Error in Function [SearchHits::GetHitAddress()]"
<< std::endl << "Parameter [hitNumber] out of bounds: "
<< hitNumber << " Upper Limit: " << hitContents.size()
<< std::endl;
throw new std::invalid_argument(
"Error in Function [SearchHits::GetHitAddress()] Parameter [hitNumber] out of bounds: "
+ std::to_string(hitNumber));
}
}
bool SearchHits::Merge(SearchHits hits) {
bool overallResult = true;
unsigned int i = 0;
while ((i < hits.CountHits()) && overallResult) {
bool tempResult = false;
unsigned char attemptNum = 1;
while ((tempResult == false) && (attemptNum++ <= 5)) {
tempResult = this->AddHit(hits.GetHit(i),hits.GetHitAddress(i));
}
overallResult = (overallResult && tempResult);
++i;
}
if (overallResult) {
hits.~SearchHits();
}
return overallResult;
}
改变
long GetHitAddress(unsigned int hitNumber)
至
long SearchHits::GetHitAddress(unsigned int hitNumber)
我在尝试构建项目时遇到以下链接器问题。
我浏览了这里的其他帖子,据我所知,我使用的唯一外部组件是标准成员(并用 std:: 标识)或原语。有什么明显的东西是我在这里遗漏的吗?
使用 Eclipse C++ (Mars) 在 Win 7 Professional 64bit 上使用内部 eclipse builder 构建。
日志:
link /debug /nologo /OUT:SAD-Snoop.exe "src\ByteScanner.obj" "src\EncType.obj" "src\SAD-Snoop.obj" "src\SearchHits.obj"
SearchHits.obj : error LNK2019: unresolved external symbol "public: long __thiscall SearchHits::GetHitAddress(unsigned int)" (GetHitAddress@SearchHits@@QAEJI@Z) referenced in function "public: bool __thiscall SearchHits::Merge(class SearchHits)" (?Merge@SearchHits@@QAE_NV1@@Z)
SAD-Snoop.exe : fatal error LNK1120: 1 unresolved externals
14:28:44 Build Finished (took 909ms)
Header:
/*
* SearchHits.h
*
* Created on: 30 Jun 2015
* Author: Nick Boyd
*/
#ifndef SEARCHHITS_H_
#define SEARCHHITS_H_
#include <iostream>
#include <string>
#include <vector>
class SearchHits {
public:
SearchHits();
~SearchHits();
bool AddHit(std::string content, long address);
unsigned int CountHits();
std::string GetHit(unsigned int hitNumber);
long GetHitAddress(unsigned int hitNumber);
bool Merge(SearchHits hits);
private:
std::vector<std::string> hits;
std::vector<long> hitAddresses;
};
#endif /* SEARCHHITS_H_ */
class:
/*
* SearchHits.cpp
*
* Created on: 30 Jun 2015
* Author: Nick Boyd
*/
#include "SearchHits.h"
#include <string>
#include <iostream>
#include <vector>
std::vector<std::string> hitContents;
std::vector<long> hitAddresses;
SearchHits::SearchHits() {
}
SearchHits::~SearchHits() {
hitContents.clear();
hitAddresses.clear();
}
bool SearchHits::AddHit(std::string hitContent, long address) {
hitContents.push_back(hitContent);
hitAddresses.push_back(address);
return ((hitContents.back() == hitContent)
&& (hitAddresses.back() == address));
}
unsigned int SearchHits::CountHits() {
return hitContents.size();
}
std::string SearchHits::GetHit(unsigned int hitNumber) {
if (hitNumber < hitContents.size()) {
return hitContents[hitNumber];
} else {
std::cout << "Error in Function [SearchHits::GetHit()]" << std::endl
<< "Parameter [hitNumber] out of bounds: "
<< hitNumber + " Upper Limit: " << hitContents.size()
<< std::endl;
throw new std::invalid_argument(
"Error in Function [SearchHits::GetHit()] Parameter [hitNumber] out of bounds: "
+ std::to_string(hitNumber));
}
}
long GetHitAddress(unsigned int hitNumber) {
if (hitNumber < hitContents.size()) {
return hitAddresses[hitNumber];
} else {
std::cout << "Error in Function [SearchHits::GetHitAddress()]"
<< std::endl << "Parameter [hitNumber] out of bounds: "
<< hitNumber << " Upper Limit: " << hitContents.size()
<< std::endl;
throw new std::invalid_argument(
"Error in Function [SearchHits::GetHitAddress()] Parameter [hitNumber] out of bounds: "
+ std::to_string(hitNumber));
}
}
bool SearchHits::Merge(SearchHits hits) {
bool overallResult = true;
unsigned int i = 0;
while ((i < hits.CountHits()) && overallResult) {
bool tempResult = false;
unsigned char attemptNum = 1;
while ((tempResult == false) && (attemptNum++ <= 5)) {
tempResult = this->AddHit(hits.GetHit(i),hits.GetHitAddress(i));
}
overallResult = (overallResult && tempResult);
++i;
}
if (overallResult) {
hits.~SearchHits();
}
return overallResult;
}
改变
long GetHitAddress(unsigned int hitNumber)
至
long SearchHits::GetHitAddress(unsigned int hitNumber)