【发布时间】:2015-03-21 01:35:12
【问题描述】:
我在编译我的项目时收到一条错误消息,我找到了与these 相同的问答,但它对我没有帮助。我不明白我的错误在哪里以及如何解决它。我使用 Mac OS X 并且我有一个 Xcode,但它不是 Xcode 项目。
我的错误:
g++ cleanup_agent.cc -o cleanup_agent -lcurl
Undefined symbols for architecture x86_64:
"reader(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
_main in cleanup_agent-12c8ac.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [build] Error 1
我的树:
.
├── Makefile
├── bad_words.txt
├── cleanup_agent.cc
├── src
│ ├── reader.cc
│ ├── reader.h
│ └── stdafx.h
└── test
└── unittest.cc
生成文件:
CC = g++
STDIN = cleanup_agent.cc
STDOUT = cleanup_agent
build: $(STDIN)
$(CC) $(STDIN) -o $(STDOUT) -lcurl
cleanup_agent.cc:
#include "src/stdafx.h"
#include "src/reader.h"
int main() {
vector<string> bad_words;
bad_words = reader("bad_words.txt");
}
reader.h:
#ifndef CLEANUP_AGENT_SRC_READER_H_
#define CLEANUP_AGENT_SRC_READER_H_
vector<string> reader(string filename);
#endif
reader.cc:
#include "stdafx.h"
#include "reader.h"
#include <fstream>
vector<string> reader(string filename) {
vector<string> data;
fstream file;
file.open(filename, fstream::in);
if (file.good()) {
string line;
while (getline(file, line)) {
data.push_back(line);
}
} else {
cout << "file not found." << endl;
}
file.close();
return data;
}
【问题讨论】:
-
你没有编译/链接
reader.cc。