CUDA(5.5)与MySQL 5.6的rint函数定义冲突引起的VS编译器C2264错误

向CUDA project中添加了如下的包含目录后:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include;
..\include_p;
..\include_p\gdal;
..\include_p\mysql;
..\include;
..\include_cg;
$(IncludePath)

在main.cu中添加如下包含文件:

#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <cuda_runtime.h>
#include <cuda_runtime_api.h>
#include <cuda_device_runtime_api.h>

#include "cuda_helloworld_kernel.cu"
#include "host_rapc_cuda.cu"

而host_rapc_cuda.cu文件又包含了:

#include "gt_geometry.h"
#include "phd_rapc_vtx.h"//该文件包含了gt_datasource.h文件,后者又包含了mysql_global.h文件,与CUDA的math_functions.h中定义的相同名称的rint函数引起了冲突
#include "gt_geometryoverlay_phdpaper.h"

编译项目,出现下面的症状:

错误    433    error C2264: “rint”: 函数定义或声明中有错误;未调用函数    c:\program files\nvidia gpu computing toolkit\cuda\v5.5\include\math_functions.h    11639

分析:

CUDA的rint函数定义在math_functions.h中,实现如下:

static __inline__ __host__ __device__ float rint(float a)
{
  return rintf(a);
}

mysql的rint的函数定义在my_global.h中,实现如下:

#ifndef HAVE_RINT
/**
  All integers up to this number can be represented exactly as double precision
  values (DBL_MANT_DIG == 53 for IEEE 754 hardware).
*/
#define MAX_EXACT_INTEGER ((1LL << DBL_MANT_DIG) - 1)

/**
  rint(3) implementation for platforms that do not have it.
  Always rounds to the nearest integer with ties being rounded to the nearest
  even integer to mimic glibc's rint() behavior in the "round-to-nearest"
  FPU mode. Hardware-specific optimizations are possible (frndint on x86).
  Unlike this implementation, hardware will also honor the FPU rounding mode.
*/

static inline double rint(double x)
{
  double f, i;
  f = modf(x, &i);

  /*
    All doubles with absolute values > MAX_EXACT_INTEGER are even anyway,
    no need to check it.
  */
  if (x > 0.0)
    i += (double) ((f > 0.5) || (f == 0.5 &&
                                 i <= (double) MAX_EXACT_INTEGER &&
                                 (longlong) i % 2));
  else
    i -= (double) ((f < -0.5) || (f == -0.5 &&
                                  i >= (double) -MAX_EXACT_INTEGER &&
                                  (longlong) i % 2));
  return i;
}
#endif /* HAVE_RINT */

由此可见,mysql和CUDA中对rint函数的重复定义在编译时引起了混淆,而mysql中的rint函数可以通过定义HAVE_RINT宏进行控制,我们在gts_cg_port.h头文件中添加定义:

#define HAVE_RINT 1

重新编译gtcg库后,再重新编译我们的CUDA工程,错误消失,编译成功。

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值