nvcc compile errors with with CUDA 6.0, clang, OS X 10.9 when including Boost.Function or opencv

I have some compile issues with both Boost.Function and opencv. The corresponding errors also occur if I only include one of those files at a time. I’m not sure if they are related, but I noticed them at the same time.

The file I am compiling is:

#include <boost/function.hpp>
#include <opencv2/opencv.hpp>

The command to compile is:

nvcc -I "/usr/local/Cellar/boost-libstdcxx/1.55.0/include" -I/usr/local/Cellar/opencv-libstdcxx/2.4.8.2/include/opencv main.cu

For Boost.Function the first error line is:

/usr/local/Cellar/boost-libstdcxx/1.55.0/include/boost/type_traits/is_abstract.hpp(72): error: identifier "__is_abstract" is undefined

For opencv the first error line is:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/include/emmintrin.h(1225): error: identifier "__builtin_ia32_movnti64" is undefined

(The boost assert warning has been fixed in boost develop apparently: #9392 (BOOST_NOINLINE NVCC in __HOST__) – Boost C++ Libraries)

The full verbose compile output is here: cuda failure boost/function and opencv · GitHub

Any help shedding light on this is much appreciated.

I also have this problem.

I had this problem too, trying to use OpenCV. I was able to work around it by rebuilding OpenCV with -stdlib=libstdc++, then adding a separate OpenCV wrapper class to my project that’s compiled separately with the ‘-x c++’ switch. Everything then links at the end without error. Here’s my (very basic) class, as an example.

MatWrapper.h:

#ifndef OPENCVWRAPPER_H_
#define OPENCVWRAPPER_H_

#include <string>


class MatWrapper {

public:
	MatWrapper();
	MatWrapper(unsigned char *,
			   unsigned int, unsigned int);
	virtual ~MatWrapper();

	void imread(std::string);
	void imshow();

	unsigned char *getData();
	unsigned int getRows();
	unsigned int getCols();

private:
	unsigned char *data;
	unsigned int nRows;
	unsigned int nCols;
};

#endif /* OPENCVWRAPPER_H_ */

MatWrapper.cpp

#include "MatWrapper.h"


#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

/**
 * Default constructor
 */
MatWrapper::MatWrapper() {
	this->data = NULL;
	this->nRows = 0;
	this->nCols = 0;
}

/**
 * Constructor that assigns private member variables
 */
MatWrapper::MatWrapper(unsigned char * _data,
					   unsigned int _nRows,
					   unsigned int _nCols) {
	this->nRows = _nRows;
	this->nCols = _nCols;
	this->data = new unsigned char[nRows*nCols];
	memcpy(this->data, _data, nRows*nCols);
}

/**
 * Default destructor
 */
MatWrapper::~MatWrapper() {
	delete [] this->data;
}

/**
 * Wrapper for openCVs cv::imread method
 */
void MatWrapper::imread(std::string filename) {
	cv::Mat image = cv::imread(filename, CV_LOAD_IMAGE_GRAYSCALE);
	this->nRows = image.rows;
	this->nCols = image.cols;
	this->data = new unsigned char[nRows*nCols];
	memcpy(this->data, image.data, nRows*nCols);
}

/**
 * Wrapper for openCVs cv::imshow method,
 * with some added steps rolled in
 */
void MatWrapper::imshow() {
	cv::Mat image(nRows, nCols, CV_8UC1, data);
	cv::namedWindow("Display window", cv::WINDOW_AUTOSIZE);
	cv::imshow("Display window", image);
	cv::waitKey(0);
}

/**
 * Getter for raw data contained in a cv::Mat object
 */
unsigned char *MatWrapper::getData() {
	return this->data;
}

/**
 * Getter for number of rows in a cv::Mat object
 */
unsigned int MatWrapper::getRows() {
	return this->nRows;
}

/**
 * Getter for number of columns in a cv::Mat object
 */
unsigned int MatWrapper::getCols() {
	return this->nCols;
}

Here’s the output when I build my project in Nsight:

Building file: ../src/MatWrapper.cpp
Invoking: NVCC Compiler
/Developer/NVIDIA/CUDA-6.0/bin/nvcc -G -g -O0 -ccbin /usr/bin/clang -gencode arch=compute_30,code=sm_30  -odir "src" -M -o "src/MatWrapper.d" "../src/MatWrapper.cpp"
/Developer/NVIDIA/CUDA-6.0/bin/nvcc -G -g -O0 -ccbin /usr/bin/clang --compile  -x c++ -o  "src/MatWrapper.o" "../src/MatWrapper.cpp"
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
Finished building: ../src/MatWrapper.cpp
 
Building file: ../src/OpenCVTest.cu
Invoking: NVCC Compiler
/Developer/NVIDIA/CUDA-6.0/bin/nvcc -G -g -O0 -ccbin /usr/bin/clang -gencode arch=compute_30,code=sm_30  -odir "src" -M -o "src/OpenCVTest.d" "../src/OpenCVTest.cu"
/Developer/NVIDIA/CUDA-6.0/bin/nvcc --compile -G -O0 -ccbin /usr/bin/clang -g -gencode arch=compute_30,code=compute_30 -gencode arch=compute_30,code=sm_30  -x cu -o  "src/OpenCVTest.o" "../src/OpenCVTest.cu"
Finished building: ../src/OpenCVTest.cu
 
Building target: OpenCVTest
Invoking: NVCC Linker
/Developer/NVIDIA/CUDA-6.0/bin/nvcc --cudart static -L/usr/local/lib -ccbin /usr/bin/clang -link -o  "OpenCVTest"  ./src/MatWrapper.o ./src/OpenCVTest.o   -lopencv_highgui -lopencv_core
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
Finished building target: OpenCVTest

It’s not a perfect solution, but better than nothing. Hope this helps.