c++ - 库未链接并获得对“Lib::algorithmA(int const&)”错误的未定义引用
问题描述
我正在从我的讲师那里提取所有应该编译的代码,但似乎我的库文件没有正确链接,因此文件以未定义的方式运行。
我的主文件在 src 中运行,看起来像这样,在 #include <Lib.h> 语句之后有很多未使用的包含语句。
#include <iostream>
#include <Lib.h>
#include "Lib.h"
#include "../include/Lib.h"
//#include "../lib/libalgos-win.a"
using namespace std;
int main() {
//you must change/expand this code
int n = 20;
//Lib guy = new Lib();
Lib::algorithmA(n);
cout << "Successful execution" <<endl;
return 0;
}
我的 Lib.h 文件如下所示
#ifndef LIBRARY_LIB_H
#define LIBRARY_LIB_H
class Lib {
public:
static void algorithmA(const int& n);
static void algorithmB(const int& n);
static void algorithmC(const int& n);
};
#endif //LIBRARY_LIB_H
在我的 Cmake 文件中,我有以下代码:
target_link_libraries(a2-program "${PROJECT_SOURCE_DIR}/lib/libalgos-win.a")
理论上,这应该将库文件链接到我在 lib 中的库,但相反,我收到一个关于未定义引用的错误。他没有就如何编辑代码给出更多说明,所以我完全迷路了。
解决方案
推荐阅读
- sql - 如何在 Oracle 中删除视图?
- python - 我们可以使用地图搜索而不是二分搜索吗?
- visual-studio-code - VS Code API 返回带有 URI 的未知 URL 方案
- unit-testing - 使用多个值运行相同的测试 - Dart
- django - 如何为多对多字段加载 YAML 种子数据?
- python - numpy 可以用来加速填充图像像素吗?
- python - 对象没有属性
- php - 进出 php 标签会减慢整个执行过程吗?
- ruby-on-rails - 从表单标签访问 params 值以显示视图
- python - 为什么我无法在带有 BPM 传感器的 Raspberry Pi 中获得 BLE 指示响应?