OpenCV 未定义引用我自己的库中的方法
OpenCV undefined reference to my own method in library
我在OpenCV C++写了一个软件,它的结构非常合理:
- 主.cpp
- 测试FPS.cpp
- testfps.hpp
问题是我得到这两个错误
对"myTestfps1(int, int)"
的未定义引用 对"myTestfps2(int, int)"的未定义引用
这两个方法是用testfps编写的.cpp并在testfps.hpp中声明。
在主要.cpp被宣布所有必要的#include <name>
,在它们之后有#include "testfps.hpp"
主.cpp
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include "testfps.hpp"
int main(int argc, char** argv[]){
....
switch(c){
case 1: myTestfps1(a,b);break;
case 2: myTestfps2(a,b);break;
}
...
}
测试FPS.cpp
#include <opencv2/opencv.hpp>
#include <time.h>
#include <stdio.h>
#include "testfps.hpp"
int myTestfps1(int a, int b){
...
}
int myTestfps2(int a, int b){
...
}
testfps.hpp
#ifndef TESTFPS_HPP
#define TESTFPS_HPP
int myTestfps1(int a, int b);
int myTestfps2(int a, int b);
#endif
这是怎么回事?
正如Samuel指出的那样,您可能遇到的主要问题是您在编译中没有包含testfps.cpp。
如果你在带有 g++ 的 Linux 上运行,请尝试以下操作:
g++ -o testfps main.cpp testfps.cpp
无论如何,由于您正在处理C++我建议您不要使用诸如stdio.h和stdlib.h之类的C标头。改用 cstdio 和 cstdlib:
#include <cstdlib>
#include <cstdio>
最后,你对 main 的定义是错误的,argv 不是指针3:
int main(int argc, char* argv[])
或:
int main(int argc, char** argv)
相关文章:
- 没有为自己的结构调用列表推回方法
- 在他自己的方法中,有可能将一个对象取消引用到另一个对象吗
- 在c++中为我自己的基于指针的数组分配内存的正确方法
- 类无法访问自己的私有静态 constexpr 方法 - Clang bug?
- 在wxWidgets的事件中包含我自己的数据的最佳方法是什么?
- 返回自己的类型的模板类方法的正确签名
- 创建自己的异常(2种方法)C
- make 方法不更改自己的类变量而不使它们常量
- 电子内部或外部方法创建自己的右键单击上下文菜单 - Windows
- 通过我自己的实现从库中覆盖模板方法
- 将C++主方法移动到其自己的文件时发生编译器错误
- OpenCV 未定义引用我自己的库中的方法
- ctypes 自己的库加载,但无法访问函数/方法
- cpp 对象方法是否有自己的堆栈帧
- 为什么无法从模板方法访问此类自己的受保护成员?
- 自己的"Insert"方法(向量)函数模板
- 如何使从基类继承的对象访问字符方法,但有自己的结果
- 如何扩展stl类以拥有自己的方法?
- 只有 1 种方法的类,让它处理自己的互斥锁是否安全?
- c++继承.对象调用超类方法而不是自己的方法