Makefile opencv停止工作

时间:2014-06-20 07:51:50

标签: c++ opencv cuda makefile

我有使用opencv的项目的以下Makefile

CFLAGS = `pkg-config --cflags opencv`
LIBS = `pkg-config --libs opencv`

% : %.cpp
    g++ $(CFLAGS) -o $@ $< $(LIBS)
直到最近,这个工作正常。我现在得到以下错误:

/usr/bin/ld: cannot find -lcufft
/usr/bin/ld: cannot find -lnpps
/usr/bin/ld: cannot find -lnppi
/usr/bin/ld: cannot find -lnppc
/usr/bin/ld: cannot find -lcudart

pkg-config --libs opencv输出:

/usr/local/lib/libopencv_calib3d.so 
/usr/local/lib/libopencv_contrib.so 
/usr/local/lib/libopencv_core.so 
/usr/local/lib/libopencv_features2d.so 
/usr/local/lib/libopencv_flann.so 
/usr/local/lib/libopencv_gpu.so 
/usr/local/lib/libopencv_highgui.so 
/usr/local/lib/libopencv_imgproc.so 
/usr/local/lib/libopencv_legacy.so 
/usr/local/lib/libopencv_ml.so 
/usr/local/lib/libopencv_nonfree.so 
/usr/local/lib/libopencv_objdetect.so 
/usr/local/lib/libopencv_ocl.so 
/usr/local/lib/libopencv_photo.so
/usr/local/lib/libopencv_stitching.so
/usr/local/lib/libopencv_superres.so 
/usr/local/lib/libopencv_ts.a 
/usr/local/lib/libopencv_video.so 
/usr/local/lib/libopencv_videostab.so 
/usr/lib/x86_64-linux-gnu/libXext.so 
/usr/lib/x86_64-linux-gnu/libX11.so 
/usr/lib/x86_64-linux-gnu/libICE.so 
/usr/lib/x86_64-linux-gnu/libSM.so 
/usr/lib/libGL.so 
/usr/lib/x86_64-linux-gnu/libGLU.so 
-lcufft -lnpps -lnppi -lnppc -lcudart -ltbb -lrt -lpthread -lm -ldl 

我已将cuda库路径导出到LD_LIBRARY_PATH

echo $LD_LIBRARY_PATH
/usr/local/cuda-5.5/lib64

此路径确实包含库:

ls $LD_LIBRARY_PATH
libcublas_device.a   libcudart.so.5.0     libcufftw.so          libcurand.so.5.5       libnppc.so.5.5.22  libnvToolsExt.so
libcublas.so         libcudart.so.5.5     libcufftw.so.5.5      libcurand.so.5.5.22    libnppi.so         libnvToolsExt.so.1
libcublas.so.5.0     libcudart.so.5.5.22  libcufftw.so.5.5.22   libcusparse.so         libnppi.so.5.5     libnvToolsExt.so.1.0.0
libcublas.so.5.5     libcudart_static.a   libcuinj64.so         libcusparse.so.5.5     libnppi.so.5.5.22
libcublas.so.5.5.22  libcufft.so          libcuinj64.so.5.5     libcusparse.so.5.5.22  libnpps.so
libcudadevrt.a       libcufft.so.5.5      libcuinj64.so.5.5.22  libnppc.so             libnpps.so.5.5
libcudart.so         libcufft.so.5.5.22   libcurand.so          libnppc.so.5.5         libnpps.so.5.5.22

但我仍然得到错误。我运行opencv 2.4.9和cuda 5.5。我忘记了什么?

2 个答案:

答案 0 :(得分:1)

LD_LIBRARY_PATH用于运行时。对于编译,您需要使用LIBRARY_PATH。 您可以将/usr/local/cuda-5.5/lib64导出到LIBRARY_PATH,也可以在Makefile中添加LIBS的路径:

LIBS += -L/usr/local/cuda-5.5/lib64

LD_LIBRARY_PATH vs LIBRARY_PATH

答案 1 :(得分:0)

我现在这样做了:g++ -L /usr/local/cuda-5.5/lib64 pkg-config --cflags opencv -o writeFramesMainSimple writeFramesMainSimple.cpp pkg-config --libs opencv并且它有效!