如何在CMake文件中添加头文件路径 [英] How to add header file path in CMake file

查看:4403
本文介绍了如何在CMake文件中添加头文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是OpenCL的新手,但是我已经在互联网的帮助下在OpenCL中写了矢量添加代码,我已经包括一个头文件,即使用#include的CL / cl.h。我使用NVIDIA显卡,OpenCL实现是NVIDIA_GPU_Computing_SDK。我的OpenCL头文件位于此路径/ opt / NVIDIA_GPU_Computing_SDK / OpenCL / common / inc -l OpenCL(不带引号)。我可以通过在编译我的代码时添加这个路径通过linux终端运行OpenCL程序。但现在我想写这个代码的CMake文件。 CMake文件工作正常为C程序,但不是OpenCL程序,因为这个路径问题。在终端i用于输入$cmake。(不带引号),在这个$make(不带引号)后,它将搜索由cmake创建的Makefile,现在我的错误是输入命令make没有引号):致命错误:CL / cl.h:没有这样的文件或目录!现在告诉我如何将这个头文件包含到cmake文件中?

解决方案

你需要把这些行放入CMakeLists.txt :

  include_directories(/ opt / NVIDIA_GPU_Computing_SDK / OpenCL / common / inc)
link_directories(/ opt / NVIDIA_GPU_Computing_SDK / OpenCL / common /< lib或类似>)

add_executable(yourexe src1.c ...)
target_link_libraries(yourexe OpenCL)
/ pre>

但是请注意,它不可移植,因为OpenCL SDK可以在另一台机器上的其他位置。正确的方法是使用 FindOpenCL.cmake 模块。


I am new to OpenCL, but i have written vector addition code in OpenCL with the help of internet and i have included one header file i.e. CL/cl.h using #include. I am using NVIDIA graphic card and the OpenCL implementation is NVIDIA_GPU_Computing_SDK. My OpenCL header files are residing at this path "/opt/NVIDIA_GPU_Computing_SDK/OpenCL/common/inc -l OpenCL" (without quotes). I can run OpenCL programs through linux terminal by adding this path when compiling my code. But now i want to write CMake file for this code. CMake files are working fine for C programs, but not OpenCL programs because of this Path problem. In terminal i used to enter $"cmake ."(without quotes), after this $"make"(without quotes), it will search for a Makefile which is created by cmake, now my error is after entering command "make"(without quotes) : fatal error: CL/cl.h: No such file or directory! now tell me how can i include this header file into cmake file?

解决方案

You will need to put these lines into CMakeLists.txt:

include_directories(/opt/NVIDIA_GPU_Computing_SDK/OpenCL/common/inc)
link_directories(/opt/NVIDIA_GPU_Computing_SDK/OpenCL/common/<lib or something similar>)

add_executable(yourexe src1.c ...)
target_link_libraries(yourexe OpenCL)

But beware that it's not portable, because OpenCL SDK can be somewhere else on another machine. The proper way to do this is to use FindOpenCL.cmake module.

这篇关于如何在CMake文件中添加头文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆