C++链接器因符号而失败
C++ Linker failure because of symbol
我正在写一些C++代码,请注意,我是该语言的新手。我已经解决了用G++编译时的所有错误,但我似乎不明白为什么我会出现链接失败。
我已经附上了我的代码和错误:
错误:
$ g++ -std=c++11 algorithm.cpp
Undefined symbols for architecture x86_64:
"Graph::Graph()", referenced from:
_main in algorithm-14102f.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我的文件(目前不完整):
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <cstdlib>
#include <map>
using namespace std;
class Graph {
struct node { // nodes that you read
string name;
int id; // index of the node in the nodes vector
vector<int> in; // parent(s) that can lead to this node
vector<int> out; // children you can go to
node(string key, int ind, vector<int> *in = new vector<int>(), vector<int> *out = new vector<int>()) :
name(key), id(ind) {}
};
vector<node> nodes; // all the nodes in arbitrary sequential order
map <string, int> dict; // map converting the names into ids
public:
Graph(); // class constructor
void addNode(string key, int id){
node *item = new node(key, id);
}
int getNodesLength(){
return nodes.size();
}
};
int main()
{
Graph * graph = new Graph();
std::string s;
std::string word;
while(std::getline(std::cin, s)) {
for(char c : s) {
if (c == ' '){ // right side words
graph->addNode(word, graph->getNodesLength());
word = "";
} else if (c == ':') { // left side word
graph->addNode(word, graph->getNodesLength());
word = "";
} else { // letter char
word += c; //
}
}
}
return 0;
}
这意味着您没有实现Graph类的构造函数。要么不要在头中声明它(这样编译器就会为你生成一个默认的构造函数),要么如果你声明了,就实现它
Graph * graph = new Graph();
Graph
已经位于顶级命名空间中。
您还忘记提供constructor
相关文章:
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- dynamic_cast什么时候会因为隐藏符号而失败?
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- 在 Mac 上C++编译代码时处理“dyld:惰性符号绑定失败:找不到符号”错误
- GLFW的最小示例由于架构X86_64的未定义符号而失败
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- dyld:惰性符号绑定失败:找不到符号:_yylex
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- 提升 Python 导入失败,未定义包装类的符号
- 如何修复此 OpenCV 错误:断言失败((无符号)i < (无符号)cn) 在 cv::Vec<unsigned char,3>:::运算符 (), 文件
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See
- dyld:惰性符号绑定失败:找不到符号.预期在:平面命名空间
- Qt 和 CMake 失败并出现重复的符号
- 动态链接到 c++ 静态成员字段时符号查找失败
- .so中存在的符号已编译.o引用了它,但链接失败
- C/C++:将 char[] 转换为 int 失败,无符号 char[] 到 int 有效,为什么
- ld:1 个重复符号用于架构x86_64 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- 无符号长 vs size_t会导致函数过载失败
- 体系结构x86_64的未定义符号,链接器命令失败