Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to resolve "undefined reference" issues? #6

Open
JenifferWuUCLA opened this issue Jan 5, 2018 · 4 comments
Open

How to resolve "undefined reference" issues? #6

JenifferWuUCLA opened this issue Jan 5, 2018 · 4 comments

Comments

@JenifferWuUCLA
Copy link

Hi,
我在运行“示例程序73 创建包围轮廓的矩形边界”的时候,遇到了如下的程序编译错误。所以,请您帮忙看看这些编译问题是否是缺少了什么头文件没有include,还是其他的什么原因?
1、undefined reference to cv::theRNG()' 2、Multiple markers at this line - undefined reference to cv::minAreaRect(cv::InputArray const&)'
- undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)' 3、undefined reference to cv::RotatedRect::points(cv::Point
*) const'
4、undefined reference to cv::Mat::operator=(cv::Scalar_<double> const&)' 5、undefined reference to cv::circle(cv::Mat&, cv::Point_, int, cv::Scalar_ const&, int, int, int)'
6、undefined reference to cv::line(cv::Mat&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)' 7、Multiple markers at this line - undefined reference to cv::imshow(std::string const&, cv::_InputArray
const&)'
8、undefined reference to `cv::waitKey(int)'

我已经在程序中include了如下这些头文件:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
using namespace std;

@JenifferWuUCLA
Copy link
Author

JenifferWuUCLA commented Jan 5, 2018

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
using namespace std;

int main()
{
// 初始化变量和随机值
Mat image(600, 600, CV_8UC3);
RNG& rng = theRNG();

// 循环,按下ESC, Q, q键程序退出,否则有键按下便一直更新
while (1)
{
	// 参数初始化
	int count = rng.uniform(3, 103);    // 随机生成点的数量
	vector<Point> points;    // 点值

	// 随机生成点坐标
	for (int i = 0; i < count; i++)
	{
		Point point;
		point.x = rng.uniform(image.cols/4, image.cols*3/4);
		point.y = rng.uniform(image.rows/4, image.rows*3/4);

		points.push_back(point);
	}

	// 对给定的2D点集,寻找最小面积的包围矩形
	RotatedRect box = minAreaRect(Mat(points));
	Point2f vertex[4];
	box.points(vertex);

	// 绘制出随机颜色的点
	image = Scalar::all(0);
	for( int i = 0; i < count; i++ )
		circle( image, points[i], 3, Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)), CV_FILLED, CV_AA );

	// 绘制出最小面积的包围矩形
	for( int i = 0; i < 4; i++ )
		line(image, vertex[i], vertex[(i+1)%4], Scalar(100, 200, 211), 2, CV_AA);

	// 显示窗口
	imshow( "矩形包围示例", image );

	// 按下ESC, Q, 或者q,程序退出
	char key = (char)waitKey();
	if (key == 27 || key == 'q' || key == 'Q')    // 'ESC'
		break;
}

return 0;

}

@philipyexushen
Copy link

你没有链接静态库吧

@JenifferWuUCLA
Copy link
Author

Hi,请问如何“链接静态库”?有示例的命令吗?

@philipyexushen
Copy link

我不知道你是不是用的VS
如果你是用的VS的话,那就在项目配置的linker选项上添加opencv_world330.lib(我的是opencv3.3,加d的那个是调试版本的,其他版本的opencv也是一样)比如\opencv\build\x64\vc14\lib这个路径(你用Cmake编的lib可能在其他地方)
然后在linker下面的那个input选项的Additional Dependencies加上opencv_world330.lib

实测不加上就会出现和你一样的报错情况,加了就好了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants