【发布时间】:2015-01-25 12:12:28
【问题描述】:
我用 C++ OpenCV 写了一个软件,它是如此结构化:
- main.cpp
- testfps.cpp
- testfps.hpp
问题是我得到了这两个错误
对“myTestfps1(int, int)”的未定义引用
未定义对“myTestfps2(int, int)”的引用
这两个方法写在testfps.cpp中,声明在testfps.hpp中。
在main.cpp中声明了所有必要的#include <name>,在它们之后是#include "testfps.hpp"
main.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;
}
...
}
testfps.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
这是怎么回事?
【问题讨论】:
-
你真的把 testfps.cpp 添加到你的项目中了吗?
-
我在 code::blocks 上创建了一个项目,我只是构建它,bt 我不知道编译是否忽略 testfps.cpp 我该如何检查?