c++ 编译错误 - 体系结构x86_64的未定义符号
c++ Compile error - Undefined symbols for architecture x86_64
可能的重复项:
架构 i386 的未定义符号:
using namespace std;
#include <iostream>
#include <fstream>
#include <string>
#include "CorpusExp.h"
int main(int argc, char* argv[]){
ifstream infile("../DATA.txt");
string train_dir; // The training data directory
infile>>train_dir;
train_dir=train_dir.substr(6,train_dir.length());
if (argc>1){
if (strcmp(argv[1],"-s")){ // enter into CorpusExploration mode
CorpusExp ce(train_dir,"all"); //<<=======LINE X!!!!!!!!
//ce.calculate();
if (argc>=3 && strcmp(argv[2],"-u")){ // check user stats
cout<<"shit";
}
else if (argc>=3 && strcmp(argv[2],"-m")){ // check movie stats
}else{ // check the all (default) stats
}
}else if(strcmp(argv[1],"-m")) {// enter into Recommendation mode
}
}
return 0;
}
如果我包含 LINE X,主.cpp将无法编译,错误消息是:
Undefined symbols for architecture x86_64:
"CorpusExp::CorpusExp(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [recommend] Error 1
这是我的CorpusExp.cpp和CorpusExp.h:
/* CorpusExporater 头文件 用于统计目的
*/
using namespace std;
#include <iostream>
#include <fstream>
#include <string>
#include <dirent.h> // the Linux library to read the directories
class CorpusExp{
public:
CorpusExp(const string&,const string&); // (dir_name, mode)
void calculate();
void display(ostream &out, const int&); // print out the id's stat information
private:
string _dir_name;
int _movie_count;
int _user_count;
int _movie_rated_count[5]; // times of movie rated as 1,2,3,4,5
float _movie_avg; // total moview average rates
string _mode; // the mode of current task
int _id; // the id of current task
};
/*CorpusExporater cpp file
Used for statistical purpose
*/
#include "CorpusExp.h"
CorpusExp::CorpusExp(const string &dir_name, const string &mode):
_dir_name(dir_name),
_mode(mode),
_movie_count(0),
_user_count(0)
{
}
void CorpusExp::calculate(){
DIR *dpdf;
struct dirent *epdf;
dpdf = opendir(strdup(_dir_name.c_str()));
if (dpdf!=NULL){
while(epdf = readdir(dpdf)){
cout<<epdf->d_name<<endl;
}
}
}
void CorpusExp::display(ostream &out, const int &id){
}
我对c ++几乎不陌生,所以我很困惑,不知道是哪个部分导致了这个问题。如果我删除 LINE X,一切都会好起来的,但是如果我在主函数中声明 CorpusExp 类,那么它就没有编译......
这是编译文件:
# Makefile for Movie Recommendation--- HW5 of Search Engine 11-641
# Yitong Zhou
# Nov 19, 2012
#source code directory:
src=src
#obj code directory:
obj=obj
recommend: $(obj)/main.o $(obj)/CorpusExp.o
g++ -o $@ $<
$(obj)/main.o: src/main.cpp src/CorpusExp.cpp
g++ -c $< -o $@
$(obj)/CorpusExp.o: $(src)/CorpusExp.cpp $(src)/CorpusExp.h
g++ -c $< -o $@
clean:
rm -rf obj/*.o recommend
尝试在没有makefile的情况下进行简单的命令行编译,以确保makefile本身不是问题。
cd src; g++ main.cpp CorpusExp.cpp -o recommend
相关文章:
- vscode g++链路故障:体系结构x86_64的未定义符号
- 体系结构x86_64的未定义符号:std:terminate(),typeinfo,运算符delete[],运算符new
- C++ 中 dlsym 的未定义符号
- 仅在 MacOS 上析构函数的未定义符号
- OSX clang++:用于 cpp 文件中显式实例化模板的体系结构x86_64的未定义符号
- PCL 出错:体系结构x86_64 @pcl的未定义符号
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 体系结构x86_64的未定义符号:链接器错误
- C++ std::vector<int> 体系结构的未定义符号 x86_64:
- 生成文件:体系结构x86_64的未定义符号
- libc++abi未定义符号:_ZTVN10__cxxabif120__si-class_type_infoE
- Xcode"体系结构x86_64的未定义符号"
- 体系结构x86_64的未定义符号:找不到原因
- SWIG链接器:未定义符号:_ZN2cv8fastFreeEPv(cv::fastFree(void*))
- 如何修复架构x86_64的未定义符号,Boost Asio 1.58
- 在Qt5上去静态库:架构的未定义符号x86_64:
- 体系结构x86_64的未定义符号:c++/ h 文件和 cpp 文件
- 监视 SDK 下的未定义符号"__Unwind_SjLj_Unregister"
- 使用 Boost/Python 的未定义符号 - 复杂
- 建筑x86_64的未定义符号:"vtkDebugLeaksManager::vtkDebugLeaksManager()",引用自: