undefined reference to `cv::imread(std::string const&, int)' in opencv

hello everyone

i am using opencv with cuda 6.5 , when i try to compile this code:

#include <opencv2/opencv.hpp>
#include <opencv2/gpu/gpu.hpp>
#include <stdio.h>
using namespace cv;

int main() {
Mat src = imread("mini.jpg", 0);

if (!src.data) exit(1);
gpu::GpuMat d_src(src);
gpu::GpuMat d_dst;
gpu::bilateralFilter(d_src, d_dst, -1, 50, 7);
gpu::Canny(d_dst, d_dst, 35, 200, 3);
Mat dst(d_dst);
imwrite("out.png", dst);
return 0;

i got those errors:

ubuntu32@Dell32:~/Templates/openCV$ nvcc gpu.cu `pkg-config --cflags
--libs opencv` /tmp/tmpxft_000016c6_00000000-16_gpu.o: In function `main': tmpxft_000016c6_00000000-3_gpu.cudafe1.cpp:(.text+0x63): undefined reference to `cv::imread(std::string const&, int)' tmpxft_000016c6_00000000-3_gpu.cudafe1.cpp:(.text+0x1bc): undefined reference to `cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)' collect2: error: ld returned 1 exit status

what is the result of:

pkg-config --cflags --libs opencv

on your machine?

anyway the problem is that you are not linking against the proper opencv libraries

This is the output I get upon executing pkg-config --cflags --libs opencv

I added all these to g++ / nvcc and tried compiling still getting the error “Undefined reference to imread…”

-I/usr/local/include -L/usr/local/lib -lopencv_dnn -lopencv_highgui -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_videoio -lopencv_imgcodecs -lopencv_features2d -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core