Makefile:在linux上构建c ++文件,无法在opencv 2.4.6中找到cuda库

时间:2014-03-22 15:46:13

标签: linux opencv cuda makefile

希望有人可以帮忙解决这个问题。

在Linux上使用Cuda Toolkit 5.5重建OpenCV 2.4.6后,尝试使用via make和CLI g ++命令构建一个引用OpenCV和CUDA的c ++文件。每种方法的输入和输出如下所示。

Makefile尝试从OpenCV引用* .a文件,但不成功。 CLI g ++命令尝试引用* .so文件,但是,某些方法似乎未定义。

Makefile是否有必要只访问OpenCV * .a文件?

生成文件:

CFLAGS = -g Wall 
LIBPATH = /data/content/cuda/opencv-2.4.6/lib
LIBS = -lopencv_calib3d_pch_dephelp -lopencv_contrib_pch_dephelp -lopencv_core_pch_dephelp -lopencv_features2d_pch_dephelp -lopencv_flann_pch_dephelp -lopencv_gpu_pch_dephelp -lopencv_haartraining_engine -lopencv_highgui_pch_dephelp -lopencv_imgproc_pch_dephelp -lopencv_legacy_pch_dephelp -lopencv_ml_pch_dephelp -lopencv_nonfree_pch_dephelp -lopencv_objdetect_pch_dephelp -lopencv_perf_calib3d_pch_dephelp -lopencv_perf_core_pch_dephelp -lopencv_perf_features2d_pch_dephelp -lopencv_perf_gpu_pch_dephelp -lopencv_perf_highgui_pch_dephelp -lopencv_perf_imgproc_pch_dephelp -lopencv_perf_nonfree_pch_dephelp -lopencv_perf_objdetect_pch_dephelp -lopencv_perf_photo_pch_dephelp -lopencv_perf_stitching_pch_dephelp -lopencv_perf_superres_pch_dephelp -lopencv_perf_video_pch_dephelp -lopencv_photo_pch_dephelp -lopencv_stitching_pch_dephelp -lopencv_superres_pch_dephelp -lopencv_test_calib3d_pch_dephelp -lopencv_test_contrib_pch_dephelp -lopencv_test_core_pch_dephelp -lopencv_test_features2d_pch_dephelp -lopencv_test_flann_pch_dephelp -lopencv_test_gpu_pch_dephelp -lopencv_test_highgui_pch_dephelp -lopencv_test_imgproc_pch_dephelp -lopencv_test_legacy_pch_dephelp -lopencv_test_ml_pch_dephelp -lopencv_test_nonfree_pch_dephelp -lopencv_test_objdetect_pch_dephelp -lopencv_test_photo_pch_dephelp -lopencv_test_stitching_pch_dephelp -lopencv_test_superres_pch_dephelp -lopencv_test_video_pch_dephelp -lopencv_ts_pch_dephelp -lopencv_video_pch_dephelp -lopencv_videostab_pch_dephelp -lopencv_gpu -lopencv_highgui
INCLUDEPATH1 = /usr/include/opencv2/core
INCLUDEPATH2 = /usr/include/opencv2/highgui 
INCLUDEPATH3 = /usr/include/opencv2/gpu 

all: tiff2png1.so

tiff2png1.so: main.o 
    g++ -o tiff2png1.so main.o  **-L $(LIBPATH) $(LIB)**

main.o: main.cpp 
    g++ -c main.cpp -g -Wall -I $(INCLUDEPATH1)  -I $(INCLUDEPATH2)  -I $(INCLUDEPATH3) $(LIBPATH)

.PHONY: clean
clean:
    rm -vf tiff2png1.so *.o

Makefile输出:

g ++ -o tiff2png1.so main.o -L /data/content/cuda/opencv-2.4.6/lib main.o:在函数main': /home/.../main.cpp:13: undefined reference to cv :: gpu :: getCudaEnabledDeviceCount()&#39; /home/.../main.cpp:15:未定义引用cv::gpu::getDevice()' /home/.../main.cpp:21: undefined reference to cv :: imread(std :: basic_string,std :: allocator&gt; const&amp;,int)&#39; /home/.../main.cpp:27:未定义引用cv::gpu::GpuMat::GpuMat(cv::Mat const&)' /home/.../main.cpp:29: undefined reference to cv :: gpu :: Stream :: Null()&#39; /home/.../main.cpp:29:对cv::gpu::resize(cv::gpu::GpuMat const&, cv::gpu::GpuMat&, cv::Size_<int>, double, double, int, cv::gpu::Stream&)' /home/.../main.cpp:42: undefined reference to cv的未定义引用:: Mat :: Mat(cv :: gpu :: GpuMat const&amp;)&#39; /home/.../main.cpp:49:未定义引用cv::_InputArray::_InputArray(cv::Mat const&)' ... main.o: In function ~GpuMat&#39;:/usr/include/opencv2/core/gpumat.hpp:374:未定义引用`cv :: gpu :: GpuMat ::释放()&#39; collect2:ld返回1退出状态 make: * [tiff2png1.so]错误1

命令行构建

$ g ++ -o tx.exe main.o -L / data / content / cuda / opencv-2.4.6 / lib -lopencv_gpu

命令行构建输出

/data/content/cuda/opencv-2.4.6/lib/ libopencv_gpu.so:未定义引用到`cv :: gpu :: convertTo(cv :: gpu :: GpuMat const&amp; ,cv :: gpu :: GpuMat&amp;,double,double,CUstream_st *)&#39;

/data/content/cuda/opencv-2.4.6/lib/libopencv_gpu.so:cn ::cpu :: setTo的未定义引用(cv :: gpu :: GpuMat&amp;,cv :: Scalar_,cv: :gpu :: GpuMat const&amp;,CUstream_st *)&#39;

/data/content/cuda/opencv-2.4.6/lib/libopencv_gpu.so:cn ::cpu :: setTo的未定义引用(cv :: gpu :: GpuMat&amp;,cv :: Scalar_,CUstream_st * )&#39;

collect2:ld返回1退出状态

1 个答案:

答案 0 :(得分:1)

看起来您可能在链接器目标

中的变量末尾省略了'S'
**LIBS** = -lopencv_calib3d_pch_dephelp ...

tiff2png1.so: main.o 
    g++ -o tiff2png1.so main.o  -L $(LIBPATH) $(**LIB**)

所以-l选项没有传递给链接器

g++ -o tiff2png1.so main.o -L /data/content/cuda/opencv-2.4.6/lib **should be here** main.o