使用CUDA7.5安装OpenCV3.1& Ubuntu 16.04有奇怪的错误

时间:2016-07-07 05:04:36

标签: opencv ubuntu cuda nvcc

我刚刚开始使用CUDA 7.5彻底安装Ubuntu 16.04并且在安装OpenCV3.1时遇到了问题。

当我运行make时,我收到以下错误:

[ 9%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o
/usr/include/string.h: In function ‘void* __mempcpy_inline(void, const void, size_t)’:
/usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope
return (char *) memcpy (__dest, __src, __n) + __n;

我在各种(封闭的)github bug /问题讨论线程中找到了一个解决方案,如下所示:

 In opencv/cmake/OpencvDetectCuda.cmake, change

    set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})

 to

    set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -D_FORCE_INLINES -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})

此解决方案对我有用,但我仍然不理解原始问题或解决方案。为什么添加标志-D_FORCE_INLINE可以解决问题?为什么string.h有问题?这是(我认为)正在编译的更稳定的文件之一。我希望有任何错误与CUDA7.5或OpenCV3.1相关联吗?

如果我再次看到这个问题,我该如何认识它?

1 个答案:

答案 0 :(得分:3)

显然,/ usr / include / string.h从glib2.22变为glibc2.23(https://fossies.org/diffs/glibc/2.22_vs_2.23/string/string.h-diff.html)。添加的代码位于文件的底部,并且是:

#if defined __USE_GNU && defined __OPTIMIZE__ \
        && defined __extern_always_inline && __GNUC_PREREQ (3,2)
    # if !defined _FORCE_INLINES && !defined _HAVE_STRING_ARCH_mempcpy

    #undef mempcpy
    #undef __mempcpy
    #define mempcpy(dest, src, n) __mempcpy_inline (dest, src, n)
    #define __mempcpy(dest, src, n) __mempcpy_inline (dest, src, n)

    __extern_always_inline void *
    __mempcpy_inline (void *__restrict __dest,
                     const void *__restrict __src, size_t __n)
    {
      return (char *) memcpy (__dest, __src, __n) + __n;
    }

    # endif
    #endif

我已经看到阻止此新代码触发memcpy错误的方法是:

1只需注释掉此代码

2将D_FORCE_INLINES添加到NVCC的标志

(https://github.com/opencv/opencv/issues/6500
   Simple replace in opencv/cmake/OpencvDetectCuda.cmake

   set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})

to

   set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -D_FORCE_INLINES -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})

或者,对于类似的错误,将D_FORCE_INLINES添加到cc的ccflags(但我现在无法找到引用)

现在,我试图找出这段代码的作用......