我正在尝试编译不是我的项目。我收到此错误:
[sophie@laptop minit]$ g++ -o minit minit.cpp
/tmp/ccxr5oWl.o: In function `main':
minit.cpp:(.text+0x4e6): undefined reference to `minit::MinitAlgo::MinitAlgo(std::string)'
minit.cpp:(.text+0x66c): undefined reference to `minit::MinitAlgo::~MinitAlgo()'
minit.cpp:(.text+0x6af): undefined reference to `minit::MinitAlgo::~MinitAlgo()'
minit.cpp:(.text+0x6df): undefined reference to `minit::MinitAlgo::~MinitAlgo()'
collect2: error: ld returned 1 exit status
主程序如下(我将代码减少到最小可能的情况):
#include <iostream>
#include <sstream>
#include <string>
#include "MinitAlgo.h"
int main(int argc, char * argv[]) {
std::string fileName = "/home/table.dat";
minit::MinitAlgo m(fileName);
}
MinitAlgo.h
文件:
#ifndef MINITALGO
#define MINITALGO
#include <string>
#include <vector>
namespace minit {
class MinitAlgo {
public:
MinitAlgo(std::string filename);
~MinitAlgo();
private:
// settings
bool showDataset;
bool showRankItems;
int logTime;
int debugLevel;
int countOnly;
};
}
#endif
MinitAlgo.cpp
文件:
#include "MinitAlgo.h"
#include <string>
#include <sstream>
#include <iterator>
using namespace minit;
MinitAlgo::MinitAlgo(std::string filename) {
this->showDataset = false;
this->showRankItems = false;
this->logTime = 0;
this->debugLevel = 0;
this->countOnly = false;
}
MinitAlgo::~MinitAlgo() {
}