Android ndk 编译报错:
error: undefined reference to 'cv::imread(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, int)'
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace cv;
int main()
{
std::string image_path = "/data/000001.jpg";
Mat img = imread(image_path, IMREAD_COLOR);
if(img.empty())
{
std::cout << "Could not read the image: " << image_path << std::endl;
return 1;
}
imshow("Display window", img);
int k = waitKey(0); // Wait for a keystroke in the window
if(k == 's')
{
imwrite("starry_night.png", img);
}
return 0;
}
有网友的解决方法:
新版本的opencv 把读取从链接库libopencv_highgui中剥离出来多了一个libopencv_imgcodecs出来。因此在使用新版本的opencv的时候需要把这个连接库也加上。
转自:
编译连接imread报错undefined reference to cv::imread(std::__cxx11::basic_string - 简书
但是
project(blazefacencnn)
cmake_minimum_required(VERSION 3.10)
set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv-mobile-4.5.4-android/sdk/native/jni)
find_package(OpenCV REQUIRED core imgproc)
set(ncnn_DIR ${CMAKE_SOURCE_DIR}/ncnn-20220420-android-vulkan/${ANDROID_ABI}/lib/cmake/ncnn)
find_package(ncnn REQUIRED)
add_library(blazefacencnn SHARED blazefacencnn.cpp blazeface.cpp ndkcamera.cpp)
target_link_libraries(blazefacencnn ncnn ${OpenCV_LIBS} camera2ndk mediandk)
这是自动寻找opencv依赖库,
博客:
error: undefined reference to `cv::imread(cv::String const&, int)'问题解决方法_KayChanGeek的博客-CSDN博客
中说缺少libopencv_imgcodecs.so,因为imread属于编解码类型的,我的opencv确实没有这个,
添加引用头文件:
#include <opencv2/imgcodecs.hpp>
也报错说找不到,
undefined reference to `cv::resize_AI视觉网奇的博客-CSDN博客
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/jacke121/article/details/125040316
内容来源于网络,如有侵权,请联系作者删除!