2

After updating my OSX to 10.9 (Maverick), I cannot compile OpenCV with CUDA support. I was able to install the CUDA SDK and compile and run all samples, so it is not a CUDA problem.

I receive the following error:

[ 22%] Built target IlmImf
[ 22%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_matrix_operations.cu.o
clang: error: unsupported option '-dumpspecs'
clang: error: no input files
CMake Error at cuda_compile_generated_matrix_operations.cu.o.cmake:206 (message):
Error generating
/Users/josericardo/Downloads/opencv-2.4.6.1/build/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_matrix_operations.cu.o

Does anyone have this problem? I've searched on the net about this specific error (some suggestions for previous error like this do exist but not for this one), but without success.

Thanks so much!

4 Answers 4

2

It's an "old" problem that has appeared since the default compiler is llvm instead of gcc on Mac and it happens on OSX 10.8 too.

Pre-requisite: if you are using a new Mac, or a Mac where the developer tools were never installed until recently (say, 3 or 4 months ago), then you want to check if gcc/g++ is installed on the machine by examining the content of /usr/bin.

If gcc/g++ are not installed, then you need to install them via, e.g., homebrew.

Cmake setup: in the cmake settings, make sure that both the C and C++ CUDA host compilers are set to your install of gcc/g++, usually in /usr/local/bin. Some helpful information can be found in this question too.

1
  • Thanks for answer sansuiso. I just formatted my mac and install a fresh version of Maverick. After that, I installed the xcode command line tools. Yes, I have the gcc/g++ located in /usr/bin. However, not installed in /usr/local/bin. Using gcc/g++ from /usr/bin I received the following message: clang: error: no input files Does it means that I do not have gcc? Thanks again! Oct 28, 2013 at 17:08
2

Here's how I compiled OpenCV 2.4.8 on OSX Mavericks 10.9.1 using Xcode 5.0.2 and CUDA 5.5:

  • open CMake to set the project, and to the basic configuration
  • in latest Xcode (I think >= 5) there's no more the gcc compiler, deprecated in favor of clang, so go to the CUDA options of the CMAKE project and change CUDA_HOST_COMPILER to use "/usr/bin/clang". Luckily CUDA 5.5 supports clang and not only gcc
  • Apparently CUDA 5.5 supports only the older libstdc++ library and not the more modern libc++, so update CUDA_NVCC_FLAGS to tell mvcc to pass tell the nativa compilar to use this older library. Add "-Xcompiler -stdlib=libstdc++; -Xlinker -stdlib=libstdc++"
  • Tell also the C++ compiler that compiles the rest of the library to use libstdc++: show the advanced options of CMAKE and go to CMAKE to add "-stdlib=libstdc++" to both CMAKE_CXX_FLAGS and CMAKE_EXE_LINKER_FLAGS
1

OK, I managed to get it to work on my machine after a couple of hard working days.

I used the git version of Opencv 2.4 but I suppose it is not so different from the version you're using.

The problems I had were the following:

  • On Mac 10.9, gcc has been dropped from the distribution in profit of clang. However, CUDA refuses to be used by clang. Even setting CUDA_HOST_COMPILER to a gcc version in cmake is not enough because the linking will be done by the main compiler and does not work with clang. Furthermore CUDA does not accept a gcc version >= 4.7. Long story short I installed an older version of gcc with macports to compile all the library.
  • Problem if you use gcc instead of clang is that the call to the newest framework of QTKit (QuickTimeKit) does not compile anymore, so I had to deactivate it (you can change it in OpenCVFindLibsVideo.cmake -> set(HAVE_QTKIT NO) ).
  • I also had to install Qt5 in order to have a working GUI (otherwise the highgui module would not compile, which includes the 'imload' and 'imwrite' functions)
  • Also do not use cmake 2.8.12 but 2.8.11 which has a bug for some linker options -> http://comments.gmane.org/gmane.comp.programming.tools.cmake.user/48007
  • You also have to set CMAKE_SYSTEM_PROCESSOR. If unset it generates an error in FindCUDA.cmake lines 762 and 770.

Probably I forgot a couple of things, I think I had to deactivate ffmpeg as well. That was pretty difficult in the end, but everything seems to work now :-)

2
  • Hello, these tips really help me out. However, if I remove the QTKit from OpenCV my webcam (iSight) does not work anymore. Have you encountered this problem? Is that another 3rd-party lib that can do camera access on OS X?
    – G. Führ
    Nov 18, 2013 at 15:23
  • Indeed, that is to be expected. I am using OpenCV to process images from the drive, so I was not interested in the issue. I suppose other libraries can do the trick but unfortunately I have no idea. A quick glance at OpenCVFindLibsVideo.cmake should inform you about the possible candidates. Nov 18, 2013 at 17:45
1

The solution posted by @Marco was the one that worked for me. However, there is an additional note that should be made. Since we have compiled OpenCV with libstdc++ we will have to change our own apps to also link with this stdlib. If we try to compile without the libstdc++ flag we get the undefined symbols linking error, similar to this:

Undefined symbols for architecture x86_64:
    "cv::imwrite(cv::String const&, cv::_InputArray const&, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
    lbp::LBP::saveLBPImage(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in LBP.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
1
  • Doing this the previous error is gone, but then "~/resources/includes/opencv2/hal/defs.h:271:14: 'cstdint' file not found" error appears. Any sugestion?
    – goe
    Dec 15, 2015 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.