如何让gcc中的链接器识别OpenCL库函数?

发布于 2024-08-08 23:53:31 字数 530 浏览 4 评论 0原文

我正在尝试使用 OpenCL。不过,我确信这个问题并不是 OpenCL 特有的。

我的主文件顶部如下所示:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <OpenCL/opencl.h>

// some code

cl_device_id device_id; //declaring a device id gives no errors

int err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);
//the above API call does give an error.

我正在 Snow Leopard 上执行此操作。我可以使用 XCode 构建并运行 Apple 的示例。我还可以通过运行 make 来编译并运行 NVIDIA 的示例代码。

如何在不使用 XCODE 的情况下正确编译我的代码?

I'm getting my feet wet with OpenCL. I'm sure this problem is not specific to OpenCL, however.

the top of my main file looks like:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <OpenCL/opencl.h>

// some code

cl_device_id device_id; //declaring a device id gives no errors

int err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);
//the above API call does give an error.

I'm doing this on Snow Leopard. I can build and run Apple's examples using XCode. I can also compile and run NVIDIA's sample code by running make.

How do I properly compile my code without using XCODE?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时间海 2024-08-15 23:53:31
$ gcc -framework OpenCL hello.c

两者都

$ gcc -framework opencl hello.c

有效。有人想在非 OSX 环境中尝试一下吗?

$ gcc -framework OpenCL hello.c

and

$ gcc -framework opencl hello.c

both work. Anyone want to try this on a non-OSX environment?

等风来 2024-08-15 23:53:31

我使用 Eclipse CDT 构建了一些简单的示例。
我还需要在 XCode 之外将 #include 更改为 #include,并添加 -I / System/Library/Frameworks/OpenCL.framework/Headers (或类似的东西)。

I built some simple examples using Eclipse CDT.
I needed to also change #include <OpenCL/opencl.h> to #include <opencl.h> outside of XCode, and add -I /System/Library/Frameworks/OpenCL.framework/Headers (or something similar).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文