Using Cmake I attempted to compile openCV 3.4.4.
If I set BUILD_TESTS or BUILD_EXAMPLES, make fails with a large number of errors: undefined reference to cv::...
If I clear BUILD_TESTS and BUILD_EXAMPLES, make completes successfully but I get the same sort of errors: undefined reference to cv::... when I try to link my application.
For example with BUILD_TESTS set, I get:
Linking CXX executable ../../bin/opencv_test_cudalegacy
CMakeFiles/opencv_test_cudalegacy.dir/__/cudalegacy/test/test_calib3d.cpp.o: In function
cv::Mat::Mat(cv::cuda::GpuMat const&)':
/home/logika-md/opencv/modules/core/include/opencv2/core/cuda.inl.hpp:624: undefined reference to cv::cuda::GpuMat::download(cv::debug_build_guard::_OutputArray const&) const'
/home/logika-md/opencv/modules/core/include/opencv2/core/cuda.inl.hpp:624: undefined reference to
cv::cuda::GpuMat::download(cv::debug_build_guard::_OutputArray const&) const'
CMakeFiles/opencv_test_cudalegacy.dir/__/cudalegacy/test/test_labeling.cpp.o: In function cv::cuda::GpuMat::GpuMat(cv::debug_build_guard::_InputArray const&, cv::cuda::GpuMat::Allocator*)':
/home/logika-md/opencv/modules/core/include/opencv2/core/cuda.inl.hpp:112: undefined reference to
cv::cuda::GpuMat::upload(cv::debug_build_guard::_InputArray const&)'
CMakeFiles/opencv_test_cudalegacy.dir/__/cudalegacy/test/test_labeling.cpp.o: In function cv::Mat::Mat(cv::cuda::GpuMat const&)':
/home/logika-md/opencv/modules/core/include/opencv2/core/cuda.inl.hpp:624: undefined reference to
cv::cuda::GpuMat::download(cv::debug_build_guard::_OutputArray const&) const'
../../lib/libopencv_ts.a(cuda_test.cpp.o): In function cvtest::loadMat(cv::Mat const&, bool)':
/home/logika-md/opencv/modules/ts/src/cuda_test.cpp:113: undefined reference to
cv::cuda::GpuMat::upload(cv::debug_build_guard::_InputArray const&)'
../../lib/libopencv_world.so.3.4.4: undefined reference to cv::_InputArray::getGpuMat() const'
../../lib/libopencv_world.so.3.4.4: undefined reference to
cv::cuda::GpuMat::setTo(cv::Scalar_<double>, cv::debug_build_guard::_InputArray const&, cv::cuda::Stream&)'
../../lib/libopencv_world.so.3.4.4: undefined reference to cv::cuda::GpuMat::convertTo(cv::debug_build_guard::_OutputArray const&, int, cv::cuda::Stream&) const'
These references all happen to be to Cuda functions but it seems that the problem occurs with all functions in the opencv_world library. I found some reference to an "-as-needed" switch on the linker that might be relevant but it wasn't clear to me how it applied.
I would be grateful for any pointers as to what I'm doing wrong.