2015-09-09 60 views
1

我在Windows上完成了一些CUDA編程,現在我想學習OpenCL。我有Macbook視網膜,其中包含Intel Iris圖形卡。我已經有xCode。我試圖在網上找到很多關於如何檢查OpenCL是否已經安裝在我的Mac上的,但我無法理解正確的方法。我剛剛看到Macbook會自動獲得OpenCL與xCode一起安裝。在Mac上使用OpenCL與xCode

我寫這都與OpenCL的幾行字,但它拋出錯誤:

Undefined symbols for architecture x86_64: 
    "_clGetPlatformIDs", referenced from: 
     _main in main.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

我完全新的OpenCL和無法理解的事情是如何與OpenCL的工作。

我的代碼:

#ifdef __APPLE__ 
#include "OpenCL/opencl.h" 
#else 
#include "CL/cl.h" 
#endif 

#include <iostream> 
using namespace std; 

int main() 
{ 
    cl_uint platformIdCount = 0; 
    clGetPlatformIDs (0, nullptr, &platformIdCount); 

    cout<<"Test openCL"; 
    return 0; 
} 

PS:的頭文件列入不會引發任何錯誤。由於在main()中的clGetPlatformIDs()發生錯誤。

回答

2

您需要鏈接到OpenCL框架。這包括將-framework OpenCL添加到您的命令行,或者如果您正在使用Xcode將OpenCL.framework添加到Link Binary With Libraries section in Build Phase

+0

與你的建議,沒有錯誤的代碼,我在我的帖子中提到,但示例代碼在SO('http:// stackoverflow.com/a/7898347/2386113')仍然拋出錯誤的' cl_device_id * devices = calloc(sizeof(cl_device_id),num_devices);'。錯誤說:'不能初始化一個類型爲cl_device_id的變量' – user2756695

+0

如果你讀了整個錯誤信息,它會告訴你,你正在給'cl_device_id *'分配一個'void *'。只需將'calloc'調用的結果投射到'cl_device_id *'。 – jprice

+0

非常感謝。有效。 – user2756695