体系结构x86_64的未定义符号:El Capitan
Undefined symbols for architecture x86_64: El Capitan
我正在使用Mac OSX 10.11 El Capitan
。
以前我使用的是OSX 10.10
。我的旧版本OSX运行的是gcc 4.9
和g++ 4.9
。但是在升级到OSX 10.11
之后,所有C++程序都开始编译失败。
然后我在OSX 10.11
中切换回gcc 4.2
,得到以下错误:
Undefined symbols for architecture x86_64:
"Graph::BFS(int)", referenced from:
_main in BFS-e06012.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我试过了所有可用的答案。我尝试运行以下命令:
$ g++ -stdlib=libstdc++ BFS.cc -o BFS
$ g++ -lstdc++ BFS.cc -o BFS
$ gcc -lstdc++ BFS.cc -o BFS
$ g++ BFS.cc
但对我来说什么都不管用。
当我在外壳上发射gcc --version
时。我得到了这个:
gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.2.0
Thread model: posix
我试图运行的程序是BFS.cc
,如下所示:
/*
* Algo: BFS
*/
#include <iostream>
#include <list>
using namespace std;
class Graph {
int V;
list<int> *adj;
public:
Graph(int V);
void addEdge( int v, int w);
void BFS(int s);
};
Graph::Graph(int V) {
this->V = V;
adj = new list<int> [V];
}
void Graph::addEdge(int v, int w) {
adj[v].push_back(w);
}
int main(int argc, char const *argv[]) {
Graph g(4);
g.addEdge(0, 1);
g.addEdge(0, 2);
g.addEdge(1, 2);
g.addEdge(2, 0);
g.addEdge(2, 3);
g.addEdge(3, 3);
cout << "Following is Breadth First Traversal (starting from vertex 2) n";
g.BFS(2);
return 0;
}
有人能帮我吗?
在您的代码中,您缺少Graph::BFS(int)
实现,但它是在类定义中定义的:
void BFS(int s);
如果您不使用此方法(它将被优化器删除),这甚至会起作用,但是,您在代码中使用它,并且此方法没有实现。
所以这不是操作系统/编译器的错误,而是您自己的错误。更重要的是,这段代码以前甚至不能链接,所以你可能需要更改它。
相关文章:
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 将无符号char*转换为std::istream*C++
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- vscode g++链路故障:体系结构x86_64的未定义符号
- 从矢量<无符号字符>转换为字符* 包括垃圾数据
- 如何理解将半精度指针转换为无符号长指针和相关的内存对齐
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 使用gcc从静态链接的文件中查找可选符号
- C++中无符号字符溢出
- 使用无符号字符数组有效存储内存
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- VC++本机单元测试,找不到调试符号
- 为什么我必须在C++中添加一个赋值符号来声明一个数组
- 检查TCHAR数组输入是否为带符号整数C++
- 用符号版本替换对函数的所有调用
- 未解析的外部符号_MsiLocateComponentW@12.
- 如何打印boost多精度128位无符号整数
- 体系结构x86_64的未定义符号:El Capitan
- 在 Xcode 7.01 上C++ 关于 El Capitan 错误 -> 体系结构的未定义符号 x86_64: