0

Hopefully someone can help with this.

After rebuilding OpenCV 2.4.6 with Cuda Toolkit 5.5 on linux, an attempt was made to build a single c++ file that references OpenCV and CUDA using via make and a CLI g++ command. The input and output from each approach are shown below.

The Makefile attempts to reference the *.a files from OpenCV, but is not successful. The CLI g++ command attempts to reference *.so files, which it seems to do, however, some methods appear to be undefined.

Is it necessary for the Makefile to access only the OpenCV *.a files?

Makefile:

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 Output:

g++ -o tiff2png1.so main.o -L /data/content/cuda/opencv-2.4.6/lib main.o: In function main': /home/.../main.cpp:13: undefined reference tocv::gpu::getCudaEnabledDeviceCount()' /home/.../main.cpp:15: undefined reference to cv::gpu::getDevice()' /home/.../main.cpp:21: undefined reference tocv::imread(std::basic_string, std::allocator > const&, int)' /home/.../main.cpp:27: undefined reference to cv::gpu::GpuMat::GpuMat(cv::Mat const&)' /home/.../main.cpp:29: undefined reference tocv::gpu::Stream::Null()' /home/.../main.cpp:29: undefined reference to 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 tocv::Mat::Mat(cv::gpu::GpuMat const&)' /home/.../main.cpp:49: undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)' ... main.o: In function~GpuMat': /usr/include/opencv2/core/gpumat.hpp:374: undefined reference to `cv::gpu::GpuMat::release()' collect2: ld returned 1 exit status make: * [tiff2png1.so] Error 1

Command Line Build

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

Command Line Build Output

/data/content/cuda/opencv-2.4.6/lib/libopencv_gpu.so: undefined reference to `cv::gpu::convertTo(cv::gpu::GpuMat const&, cv::gpu::GpuMat&, double, double, CUstream_st*)'

/data/content/cuda/opencv-2.4.6/lib/libopencv_gpu.so: undefined reference to `cv::gpu::setTo(cv::gpu::GpuMat&, cv::Scalar_, cv::gpu::GpuMat const&, CUstream_st*)'

/data/content/cuda/opencv-2.4.6/lib/libopencv_gpu.so: undefined reference to `cv::gpu::setTo(cv::gpu::GpuMat&, cv::Scalar_, CUstream_st*)'

collect2: ld returned 1 exit status

user1186233
  • 157
  • 1
  • 1
  • 11

1 Answers1

1

It looks like you may have omitted an 'S' at the end of your variable in the linker target

**LIBS** = -lopencv_calib3d_pch_dephelp ...

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

and so the -l options aren't being passed to the linker

g++ -o tiff2png1.so main.o -L /data/content/cuda/opencv-2.4.6/lib **should be here** main.o
awiseman
  • 5,539
  • 1
  • 18
  • 15
  • The "S" fix to the Makefile now makes it generate the same error as the command line. It appears that the "*.a" libraries in the Makefile are not being detected by the linker. "opencv_gpu" was added to the Makefile and it seems to be the only library getting detected. It has an ".so" extension. Thanks. – user1186233 Mar 23 '14 at 04:27
  • Are some other flags needed to get the linker to detect the *.a files? – user1186233 Mar 23 '14 at 04:55
  • I've loaded static libraries (*.a) using the -l flag before, so I know that works. I haven't tried mixing dynamic libraries (*.so), though so that could possibly be causing your problem. Maybe try this to force static linking: http://stackoverflow.com/questions/3698321/g-linker-force-static-linking-if-static-library-exists – awiseman Mar 23 '14 at 05:06
  • Also, be sure that any libraries that are dependencies of others are being loaded before the library that depends on it. – awiseman Mar 23 '14 at 05:09
  • The following error message is confusing: /data/content/cuda/opencv-2.4.6/lib/libopencv_gpu.so: undefined reference to `cv::gpu::convertTo(cv::gpu::GpuMat const&, cv::gpu::GpuMat&, double, double, CUstream_st*)'. This suggests that the opencv library is missing methods. – user1186233 Mar 23 '14 at 22:28