C++ 建筑x86_64的未定义符号(类似)
C++ Undefined symbols for architecture x86_64 (similar)
当我在编译代码时遇到困难时,我正在使用我的mbp在线练习随机问题。 我确实在网上搜索了类似的问题,但这就是我想出的,仍然无法编译。
我有错误消息
c++ test.cpp -o test
Undefined symbols for architecture x86_64:
"matrix::mSubtraction(float*, float*)", referenced from:
_main in test-fb9462.o "matrix::mMultiplication(float*, float*)", referenced from:
_main in test-fb9462.o "matrix::mShow(float*)", referenced from:
_main in test-fb9462.o "matrix::mAddition(float*, float*)", referenced from:
_main in test-fb9462.o "matrix::mDivision(float*, float*)", referenced from:
_main in test-fb9462.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: *** [test] Error 1
测试.cpp
#include <iostream>
#include "matrix.h"
using namespace std;
int main()
{
float matrix_a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
float matrix_b[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
matrix m;
m.Cols = 3;
m.Rows = 3;
cout << "Matrix A :n";
m.mShow((float *)matrix_a);
cout << "Matrix B :n";
m.mShow((float *)matrix_b);
cout << "Matrix Addition :n";
m.mAddition((float *)matrix_a,(float *)matrix_b);
m.mShow((float *)m.ans);
cout << "Matrix Subtraction :n";
m.mSubtraction((float *)matrix_a,(float *)matrix_b);
m.mShow((float *)m.ans);
cout << "Matrix Multiplication :n";
m.mMultiplication((float *)matrix_a,(float *)matrix_b);
m.mShow((float *)m.ans);
cout << "Matrix Division :n";
m.mDivision((float *)matrix_a,(float *)matrix_b);
m.mShow((float *)m.ans);
return 0;
}
矩阵.cpp
#include <iostream>
void matrix::mShow(float *A) {
for(int i = 0; i < matrix::Cols; i++) {
for (int j = 0; j < matrix::Rows; j++) {
printf("%f n",*((A+i*3)+j));
}
}
}
void matrix::mAddition(float *A, float *B) {
for(int i = 0; i < matrix::Cols; i++) {
for (int j = 0; j < matrix::Rows; j++) {
matrix::ans[i][j]= *((A+i*3) + j) + *((B+i*3) + j);
}
}
}
void matrix::mSubtraction(float *A, float *B) {
cout << "After matrix addition" << endl;
for(int i = 0; i < matrix::Cols; i++) {
for (int j = 0; j < matrix::Rows; j++) {
matrix::ans[i][j]= *((A+i*3) + j) - *((B+i*3) + j);
}
}
}
void matrix::mMultiplication(float *A, float *B) {
cout << "After matrix addition" << endl;
for(int i = 0; i < matrix::Cols; i++) {
for (int j = 0; j < matrix::Rows; j++) {
matrix::ans[i][j]= *((A+i*3) + j) * *((B+i*3) + j);
}
}
}
void matrix::mDivision(float *A, float *B) {
cout << "After matrix addition" << endl;
for(int i = 0; i < matrix::Cols; i++) {
for (int j = 0; j < matrix::Rows; j++) {
matrix::ans[i][j]= *((A+i*3) + j) / *((B+i*3) + j);
}
}
}
矩阵.h
#ifndef __MATRIX_H__
#define __MATRIX_H__
#include <iostream>
using namespace std;
class matrix {
private:
public:
int Cols;
int Rows;
float ans[3][3];
void mShow(float *);
void mAddition(float *,float *);
void mSubtraction(float *,float *);
void mMultiplication(float *,float *);
void mDivision(float *,float *a);
};
#endif
谢谢你们好心地帮助我。
c++ test.cpp -o test
这不起作用,因为您还需要链接matrix.cpp
的机器/目标代码。尝试:
c++ -c matrix.cpp
c++ -c test.cpp
c++ -o test matrix.o test.o
或者,为您的编译器提供适当的选项。
相关文章:
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 如何在c++中使用引用实现类似python的行为
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 将无符号char*转换为std::istream*C++
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- vscode g++链路故障:体系结构x86_64的未定义符号
- 使用Qt C++计算类似Git的SHA1哈希
- 从矢量<无符号字符>转换为字符* 包括垃圾数据
- 如何理解将半精度指针转换为无符号长指针和相关的内存对齐
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 使用gcc从静态链接的文件中查找可选符号
- 类似枚举的计算常量
- 是否有类似std::lower_bound的函数,而不需要排序/分区输入
- C++中无符号字符溢出
- 类似于strcat()的函数出现问题
- 使用无符号字符数组有效存储内存
- C++ 建筑x86_64的未定义符号(类似)
- 未解决的外部符号(已经阅读了类似的问题,但没有运气)
- 在C/ c++或任何其他类似语言中,对变量或数据类型应用&符号时返回的地址类型
- 为什么在c++ /Java和类似的语言中用美元符号开始变量名是不好的?