体系结构错误的未定义符号
Undefined symbol for architecture error
我有一个奇怪的"建筑未定义符号"的例子,诚然,这里已经问过很多次了,但我觉得我的错误背后的原因更根本。
我是C++新手,并且有一个不使用第三方库的非常基本的程序,因此我不明白为什么它会像这个问题的其他答案所暗示的那样,与使用不同编译器构建的库混合有关。
这是我完整的代码
src/myTest.cpp
#include <iostream>
#include "Point3D.h"
using namespace std;
using namespace lspsm;
int main(int argc, char** argv) {
Point3D p(1,2,3);
cout << p.getX() << endl;
return 0;
}
src/Point3D.h
#ifndef Point3D_H
#define Point3D_H
namespace lspsm {
class Point3D {
int p_values [3];
public:
Point3D(int x, int y, int z);
int getX();
int getY();
int getZ();
};
}
#endif
src/Point3D.cpp
#include Point3D_H
namespace lspsm {
Point3D::Point3D(int x, int y, int z) {
p_values[0] = x;
p_values[1] = y;
p_values[2] = z;
}
int Point3D::getX() {
return p_values[0];
}
int Point3D::getY() {
return p_values[1];
}
int Point3D::getZ() {
return p_values[2];
}
}
src/CMakeLists.txt
add_executable(myTest myTest.cpp)
在构建中我运行
cmake ../src
make
在我开始使用main
中的 Point3D
类之前,这工作正常,但现在我看到了错误
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mh/dev/CPP/build
[ 50%] Linking CXX executable myTest
Undefined symbols for architecture x86_64:
"lspsm::Point3D::getX()", referenced from:
_main in myTest.o
"lspsm::Point3D::Point3D(int, int, int)", referenced from:
_main in myTest.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我是否为Point3D
写错了类实现?
我正在OS X Sierra上运行它,制作3.81。
在CMakeLists.txt
中,您还需要将Point3D.cpp
添加到add_executable
源列表中:
add_executable(myTest myTest.cpp Point3D.cpp)
相关文章:
- vscode g++链路故障:体系结构x86_64的未定义符号
- 在 Mac 上使用 CMAKE 将 FFTW 和 FFTWPP 链接到项目中时未定义的符号
- 在C++中使用内联方法时出现未定义的符号错误
- 引擎节点:未定义的符号:_ZTV6Config
- 未定义的引用,尽管存在符号,但 std::experimental::可选
- 体系结构x86_64的未定义符号:std:terminate(),typeinfo,运算符delete[],运算符new
- Windows 链接器是否使用 LoadLibrary 解析 DLL 中未定义的符号?
- C++ 中 dlsym 的未定义符号
- MacOS 上的 Xcode 11 项目不在一个函数中使用 sin 和 cos:未定义的符号"___sincosf_stret"
- 仅在 MacOS 上析构函数的未定义符号
- OSX clang++:用于 cpp 文件中显式实例化模板的体系结构x86_64的未定义符号
- PCL 出错:体系结构x86_64 @pcl的未定义符号
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 从 C++ 到 Python 的 SWIG:未定义的符号导入问题
- 使用静态变量未解析的外部符号/未定义的引用时出错
- 无法导出mexfunction:符号未定义的collect.exe2.exe:错误:ld返回1退出状态
- 模板生成错误:体系结构的符号未定义 x86_64:
- 继承-符号未定义
- __next_prime符号未定义
- 错误:对cv:: videoccapture::~ videoccapture()的引用符号未定义,命令行中缺少DSO