【发布时间】:2014-10-16 08:41:58
【问题描述】:
我使用这里提到的步骤安装了 Ubuntu 14.04 和 Opencv https://solarianprogrammer.com/2014/04/21/opencv-beaglebone-black-ubuntu/
我正在尝试编译以下代码(保存在名为 test2.cpp 的文本文件中。将 test2.cpp 和 lena.jpg 复制到 beaglebone 主文件夹):
// Test to convert a color image to gray
// Build on Linux with:
// g++ test2.cpp -o test2 -lopencv_core -lopencv_imgproc -lopencv_highgui
#include <opencv2/opencv.hpp>
#include <iostream>
int main() {
// Load the image file and check for success
cv::Mat input = cv::imread("lena.jpg", 1);
if(!input.data) {
std::cout << "Unable to open the image file" << std::endl;
return -1;
}
// Convert the input file to gray
cv::Mat gray_image;
cvtColor(input, gray_image, cv::COLOR_BGR2GRAY);
// Save the result
cv::imwrite("lena_gray.jpg", gray_image);
return 0;
}
使用 g++ test2.cpp -o test2 -lopencv_core -lopencv_imgproc -lopencv_highgui 我还尝试告诉编译器库在哪里使用 -L /usr/local/lib 。 (在那里找到了 libopencv 文件)。但是每次都报错:
ubuntu@arm:~$ g++ test2.cpp -o test2 -lopencv_core -lopencv_imgproc -lopencv_highgui -L usr/local/lib
/tmp/cckXjOPd.o: In function `main':
test2.cpp:(.text+0x26): undefined reference to `cv::imread(cv::String const&, int)'
test2.cpp:(.text+0xf0): undefined reference to `cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int, std::allocator<int=""> > const&)'
collect2: error: ld returned 1 exit status
有人可以帮我吗?任何帮助将不胜感激。
【问题讨论】:
-
错字:您缺少库路径的前导
/。你需要-L /usr/local/lib。写一个Makefile可能会更容易设置这种东西。 -
我尝试添加前导 / 但得到了同样的错误。
标签: c++ opencv compilation