
[英]ndk-build giving me "error: undefined reference" to cv::CascadeClassifier::load(std::string const&) even after I link the libraries
[英]'undefined reference to `cv::cuda::resize...' when go build to link libs
我在 opencv.cpp 文件中有以下代码:
#include "opencv.hpp"
#include <stdbool.h>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/cudawarping.hpp>
#include "opencv2/cudaimgproc.hpp"
void opencv_mat_resize(const opencv_mat src,
opencv_mat dst,
int width,
int height,
int interpolation,
int hardware_acceleration)
{
if (hardware_acceleration == 0) {
cv::resize(*static_cast<const cv::Mat*>(src),
*static_cast<cv::Mat*>(dst),
cv::Size(width, height),
0,
0,
interpolation);
} else {
cv::cuda::GpuMat gpuInImage;
cv::cuda::GpuMat gpuOutImage;
gpuInImage.upload(*static_cast<const cv::Mat*>(src));
cv::cuda::resize(gpuInImage, gpuOutImage, cv::Size(width, height));
gpuOutImage.download(*static_cast<cv::Mat*>(dst));
}
}
我曾在 golang 中使用它,如下所示:
// #cgo CFLAGS: -msse -msse2 -msse3 -msse4.1 -msse4.2 -mavx
// #cgo darwin CFLAGS: -I${SRCDIR}/deps/osx/include
// #cgo linux CFLAGS: -I${SRCDIR}/deps/linux/include
// #cgo CXXFLAGS: -std=c++11
// #cgo darwin CXXFLAGS: -I${SRCDIR}/deps/osx/include
// #cgo linux CXXFLAGS: -I${SRCDIR}/deps/linux/include
// #cgo LDFLAGS: -lopencv_core -lopencv_imgcodecs -lopencv_imgproc -ljpeg -lpng -lwebp -lippicv -lz
// #cgo darwin LDFLAGS: -L${SRCDIR}/deps/osx/lib -L${SRCDIR}/deps/osx/share/OpenCV/3rdparty/lib
// #cgo linux LDFLAGS: -L${SRCDIR}/deps/linux/lib -L${SRCDIR}/deps/linux/share/OpenCV/3rdparty/lib
// #include "opencv.hpp"
import "C"
func (f *Framebuffer) ResizeTo(width, height int, dst *Framebuffer) error {
if width < 1 {
width = 1
}
if height < 1 {
height = 1
}
err := dst.resizeMat(width, height, f.pixelType)
if err != nil {
return err
}
hardwareAcceleration := os.Getenv("RESIZE_HARDWARE_ACCELERATION")
if enabled, err := strconv.ParseUint(hardwareAcceleration, 10, 64); err != nil || enabled == 0 {
C.opencv_mat_resize(f.mat, dst.mat, C.int(width), C.int(height), C.CV_INTER_AREA, C.int(0))
} else {
C.opencv_mat_resize(f.mat, dst.mat, C.int(width), C.int(height), C.CV_INTER_AREA, C.int(1))
}
return nil
}
并且go build
返回错误:
/etc/go/pkg/tool/linux_amd64/link: running g++ failed: exit status 1
/usr/bin/ld: /tmp/go-link-1971014753/000024.o: in function `opencv_mat_resize':
/home/andrew/source/.../opencv.cpp:187: undefined reference to `cv::cuda::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int, cv::cuda::Stream&)'
collect2: error: ld returned 1 exit status
环境变量:
CPLUS_INCLUDE_PATH=/usr/local/include/opencv4:/usr/local/include/opencv4:
LD_LIBRARY_PATH=:/usr/local/cuda-11.7/lib64
在我看来,这些代码在 vscode 中没有错误报告,这意味着我的 opencv 库是正确制作的。 但我无法通过go build
。 我不明白我错过了哪里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.