OpenCL编译错误C4996

OpenCL Compiler Error C4996

本文关键字:C4996 错误 编译 OpenCL      更新时间:2023-10-16

我是新手。我已经阅读了一些书籍,并尝试编译以下代码

#define __CL_ENABLE_EXCEPTIONS
#define __NO_STD_VECTOR
#define PROGRAM_FILE "blank.cl"
#define KERNEL_FUNC "blank"
//#define __MAX_DEFAULT_VECTOR_SIZE 100
#include <cstdio>
#include <fstream>
#include <iostream>
#include <iterator>
#ifdef Windows
    #include <OpenCL/cl.hpp>
#else
    #include <CL/cl.hpp>
#endif
using namespace std;
using namespace cl;
int main() {
    // int n = 10;    
    vector<Platform> platforms;
    vector<Device> devices;
    try {
    } catch (exception e) {
    }
    return 0;
}

但是它给了我很多错误。

大部分如下

Error   14  error C4996: 'cl::vector<char *,10>': was declared deprecated   C:Program Files (x86)AMD APP SDK2.9includeCLcl.hpp    1138    1   Matrix_multilpy_C

有谁能帮我吗?我使用visual studio 2013来编码,我发现我的版本是openCL 1.2

谢谢。

这很简单:cl名称空间提供了一个vector类,由于您使用了using namespace cl;,因此您将获得该类。

删除行,#include <vector>,删除__NO_STD_VECTOR定义,并简单地使用std::vector<cl::Device>, std::vector<cl::Platform>std::vector做所有需要的;由于某种原因或其他原因,OpenCL头文件用于提供自定义向量类,不应该再使用(我不知道为什么首先添加它)。

您也不应该使用std命名空间。注意,一旦同时使用clstd名称空间,代码就会失败,因为会突然出现两个向量类碰撞。所以说不!