架构x86_64的不确定符号
Clion Undefined symbols for architecture x86_64
我的代码编译并按照Codelite的预期运行。然后,我尝试在Clion中运行相同的代码,但是它给了我这个错误:
Scanning dependencies of target leastSquareFitting
[ 50%] Building CXX object CMakeFiles/leastSquareFitting.dir/main.cpp.o
[100%] Linking CXX executable leastSquareFitting
Undefined symbols for architecture x86_64:
"printMatrix(Matrix)", referenced from:
_main in main.cpp.o
"constructMatrix(int, std::__1::vector<double,
std::__1::allocator<double> >)", referenced from:
_main in main.cpp.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[3]: *** [leastSquareFitting] Error 1
make[2]: *** [CMakeFiles/leastSquareFitting.dir/all] Error 2
make[1]: *** [CMakeFiles/leastSquareFitting.dir/rule] Error 2
make: *** [leastSquareFitting] Error 2
我试图在线搜索此错误,但无法根据发现的问题来解决它。这是我的代码:
main.cpp
#include "fullMatrix.h"
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<double> value = {1.0,2.0,3.0,4.0};
Matrix m = constructMatrix(2, value);
printMatrix(m);
return 0;
}
fullmatrix.cpp
#include "fullMatrix.h"
#include <iostream>
#include <vector>
#include "cmath"
#include <cstdio>
using namespace std;
Matrix constructMatrix(int size, vector<double> x) {
//initiate variables of a matrix
Matrix myMatrix;
myMatrix.size = size;
myMatrix.value = x;
return myMatrix;
}
void printMatrix(Matrix matrix){
// Loop through rows and columns to display all values
for (int row = 0; row < matrix.size; row++) {
for (int col = 0; col < matrix.size; col++) {
cout <<matrix.value[col+row*matrix.size] << " ";
}
cout << endl;
}
}
fullmatrix.h
#ifndef fullMatrix_h
#define fullMatrix_h
#include <vector>
using namespace std;
struct Matrix
{
int size;
vector<double> value;
};
Matrix constructMatrix(int size, vector<double> x);
void printMatrix(Matrix matrix);
#endif
我对Cmake非常陌生,这就是Cmakelists中的内容:
cmake_minimum_required(VERSION 3.10)
project(leastSquareFitting)
set(CMAKE_CXX_STANDARD 11)
add_executable(leastSquareFitting main.cpp)
谢谢!任何帮助都将不胜感激!
将您的cmakelists的最后一行更改为:
add_executable(leastSquareFitting main.cpp fullMatrix.cpp)
链接器告诉您的内容是找不到包含函数printMatrix
的编译文件,如果您查看CMAKE的输出,您会看到CMAKE仅编译Main.cpp。/p>
Building CXX object CMakeFiles/leastSquareFitting.dir/main.cpp.o
它没有提及另一个文件的原因是您没有告诉它文件也是您的来源的一部分。
相关文章:
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 不确定如何装饰我的C++库代码以在 C 中使用
- C++功能泄漏内存,我是C++新手,不确定如何解决
- CMake 生成的 MSVC 项目找不到符号,即使为其相关 dll 正确生成了 lib 文件也是如此
- "错误 C0000:语法错误,令牌"<EOF>"处出现意外$end,并且不确定
- 错误:当我从"WinDbg"打开可执行文件时,找不到符号文件。默认导出 ntdll 的符号.dll
- 代码在 CodeSignal 中工作不正确。不确定这是否是我的代码缺陷
- 为什么以下代码是不确定的?
- 编译错误:"lvalue required as left operand of assignment" 不确定原因
- 误用指针会产生分段错误。我仍然不确定如何纠正它
- 我不确定为什么代码没有运行,它在编译时抛出错误,说它无法找到 PrintArray()
- 不确定出了什么问题(字符串输入)
- 代码输出随机符号,我不确定出了什么问题
- 架构x86_64的不确定符号
- liberial对符号的不确定引用
- glfw3库在带有cmake的clion中导致macOS上的不确定符号
- 对于不确定值的无符号字符类型,标准中特殊语言对于左值到右值的转换有什么意义?
- Clang Linker说符号不确定
- OpenCV符号使用GCC 5.1不确定
- 如何在不调试符号的情况下确定从外部库引发的异常