我们先新建个NVCC的编译器,
使用复制GCC编译器的方式进行新建,然后我们进行以下的路径配置
先来看看链接库,将我们经常使用的cuda库链接进来。
然后链接cuda的头文件:
接着配置调试工具以及编译链接的工具:
然后最重要的就是编辑下面的内容,这样可以确保你能够编译过。
面对这样的警告,我们选择yes就ok。
里面的内容是:
$compiler --compiler-options "$options" $includes -c $file -o $object
图片只是为了让大家能够清晰的看到。
还 还选择Compiler error,然后把regular expression中的内容替换成:有就是在Output parsing标签页中选择Instantiated from info,然后把Regular expression中的内容替换成:
([][{}() #%$~A-Za-z0-9_:+//.-]+)[(:]([0-9]+)/)?:[ ]+([iI]nstantiated from .*)
这里不放图片了,大家看到这里应该都知道如何配置了。
选择Compiler warning,然后把regular expression中的内容替换成:
([][{}() #%$~A-Za-z0-9_:+//.-]+)[(:]([0-9]+)/)?:[ ]([Ww]arning:[ ].*)
选择Compiler error,然后把regular expression中的内容替换成:
([][{}() #%$~A-Za-z0-9_:+//.-]+)[(:]([0-9]+)/)?:[ ](.*)
都 当然别高兴太早,这样还是不够滴,还需要将.cu的文件加入链接和编译的文件中,
在左边项目文件关系树的.cu文件上点击右键,然后点击Propertiies
- 在Build标签页中,选中Compile file 和 Link file
#include <stdio.h> #include <cuda_runtime.h> //头文件 //核函数声明,前面的关键字__global__ __global__ void kernel( void ) { } int main( void ) { //核函数的调用,注意<<<1,1>>>,第一个1,代表线程格里只有一个线程块;第二个1,代表一个线程块里只有一个线程。 kernel<<<1,1>>>(); printf( "Hello, World!\n" ); return 0; }
为了表示我对原作者的尊重附上两个链接:
http://bookc.github.io/2014/05/08/my-summery-the-book-cuda-by-example-an-introduction-to-general-purpose-gpu-programming/
上面是代码的来源。
下面是配置cuda到code block的文章的来源:
http://benbarsdell.blogspot.com/2009/03/cuda-in-codeblocks-first-things-second.html
欢迎参考。
https://devtalk.nvidia.com/default/topic/411413/c-cuda-integration-with-code-blocks/