Cannot use OpenCV 2.4.9 in a CUDA 6 project with nvcc compiler on Mac OSX 10.9.4 (Bug #3911)
Description
I am trying to compile the simple cuda program below which includes opencv (and actually not any Cuda code)
#include <iostream> //#include <cuda_runtime.h> #include <opencv2/core/core.hpp> using namespace std; int main(int argc, char **argv) { cout<<"Hello World:"<<endl; cout<<cv::Mat::eye(2,2,CV_32FC1)<<endl; cout<<"after opencv:"<<endl; }
with nvcc -o cudatest cudatest.cu -lopencv_core
but it is giving me the error
/usr/local/include/opencv2/core/mat.hpp(117): error: type name is not allowed /usr/local/include/opencv2/core/mat.hpp(117): error: identifier "_Atomic" is undefined /usr/local/include/opencv2/core/mat.hpp(117): error: expected an expression /usr/local/include/opencv2/core/mat.hpp(117): error: identifier "__c11_atomic_fetch_add" is undefined /usr/local/include/opencv2/core/mat.hpp(286): error: type name is not allowed
This issues seems related to this resolved issue as well as this open issue but the details given there didn't really help me to figure out what I was supposed to do.
I installed opencv succesfully using homebrew and the --with-cuda flag (so it should have been compiled with libstdc++) after I slightly patched the formula
like in this thread
I tried to track down the error, so I used different compilers (clang++ and nvcc) as well as different setting (libc++ vs libstdc++) and got the following results: (just run compilertest.sh to test on your own)
_______1: clang++ -o cudatest cudatest.cu -lopencv_core -stdlib=libc++ -std=c++11 && ./cudatest Hello World: [1, 0; 0, 1] after opencv: _______2: clang++ -o cudatest cudatest.cu -lopencv_core -stdlib=libstdc++ -std=c++11 && ./cudatest Hello World:" _______3: nvcc -o cudatest cudatest.cu -lopencv_core /usr/local/include/opencv2/core/mat.hpp(117): error: type name is not allowed /usr/local/include/opencv2/core/mat.hpp(117): error: identifier "_Atomic" is undefined /usr/local/include/opencv2/core/mat.hpp(117): error: expected an expression /usr/local/include/opencv2/core/mat.hpp(117): error: identifier "__c11_atomic_fetch_add" is undefined /usr/local/include/opencv2/core/mat.hpp(286): error: type name is not allowed ...' _______4: nvcc -o cudatest cudatest.cu --ptxas-options=-v -lopencv_core -ccbin=clang++ -Xcompiler -std=c++11 -Xlinker -stdlib=libstdc++ /Developer/NVIDIA/CUDA-6.5/bin/../include/common_functions.h(145): warning: allowing all exceptions is incompatible with previous function "operator new(size_t)" /usr/include/c++/4.2.1/new(99): here /Developer/NVIDIA/CUDA-6.5/bin/../include/common_functions.h(146): warning: allowing all exceptions is incompatible with previous function "operator new[](size_t)" /usr/include/c++/4.2.1/new(100): here /usr/local/include/opencv2/core/mat.hpp(117): error: type name is not allowed /usr/local/include/opencv2/core/mat.hpp(117): error: identifier "_Atomic" is undefined /usr/local/include/opencv2/core/mat.hpp(117): error: expected an expression /usr/local/include/opencv2/core/mat.hpp(117): error: identifier "__c11_atomic_fetch_add" is undefined /usr/local/include/opencv2/core/mat.hpp(286): error: type name is not allowed ...'
Related issues
related to Bug #3469: CV_XADD breaks build in OSX10.9 Maverick + CUDA + clang | Done | 2013-12-30 | ||
related to Bug #3831: Cannot compile OpenCV 2.4.9 + CUDA 6 with clang on Mac OS... | Open | 2014-07-27 |
Associated revisions
Merge pull request #3911 from vpisarev:core_tweaks
History
Updated by Adrian Haarbach over 10 years ago
was resolved in 2.4.10, pushed about 10 days ago
https://github.com/bhack/opencv/commit/32f6e1a554dea1849ee3a53fea171cbd5969ef41
- Status changed from Open to Done
- Target version set to 2.4.10