BdB
BdB

Reputation: 503

Makefile opencv stopped working

I have the following Makefile for projects using opencv

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

% : %.cpp
    g++ $(CFLAGS) -o $@ $< $(LIBS)

This worked fine until recently. I now get the following errors:

/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 outputs:

/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 

I have exported the cuda library path to LD_LIBRARY_PATH:

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

This path indeed contains the libraries:

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

But I still get the errors. I run opencv 2.4.9 and cuda 5.5. What am I forgetting?

Upvotes: 1

Views: 3400

Answers (2)

BdB
BdB

Reputation: 503

I now did this: g++ -L /usr/local/cuda-5.5/lib64 pkg-config --cflags opencv -o writeFramesMainSimple writeFramesMainSimple.cpp pkg-config --libs opencv and it worked!

Upvotes: 0

Elie G&#233;nard
Elie G&#233;nard

Reputation: 1683

LD_LIBRARY_PATH is for runtime. For compilation you need to use LIBRARY_PATH. Either you export /usr/local/cuda-5.5/lib64 to LIBRARY_PATH or you add the path to LIBS in your Makefile:

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

LD_LIBRARY_PATH vs LIBRARY_PATH

Upvotes: 1

Related Questions