编译和链接纯C和CUDA代码[警告:函数的隐式声明]
我正在尝试编译和链接.c和.cu文件,我得到了一个警告编译和链接纯C和CUDA代码[警告:函数的隐式声明],c,compilation,cuda,gcc-warning,nvcc,C,Compilation,Cuda,Gcc Warning,Nvcc,我正在尝试编译和链接.c和.cu文件,我得到了一个警告 warning: implicit declaration of function 我需要从.c文件调用.cu文件中的一个函数。.c文件使用gcc编译,.cu文件使用nvcc编译器编译。由于.cu文件的头文件包含内置的cuda数据类型,因此我无法将其包含在.c文件中。我仍然能够编译和链接所有的文件,但我想摆脱的警告,我不能。守则的基本结构如下: gpu.cu void fooInsideCuda(); cpu.c fo
warning: implicit declaration of function
我需要从.c文件调用.cu文件中的一个函数。.c文件使用gcc编译,.cu文件使用nvcc编译器编译。由于.cu文件的头文件包含内置的cuda数据类型,因此我无法将其包含在.c文件中。我仍然能够编译和链接所有的文件,但我想摆脱的警告,我不能。守则的基本结构如下:
gpu.cu
void fooInsideCuda();
cpu.c
fooInsideCuda(); //calling function in gpu.cu
任何帮助或建议都将不胜感激。此链接:
回答你的问题:,。基本上:
在.c文件中
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cuda.h>
extern void kernel_wrapper(int *a, int *b);
int main(int argc, char *argv[])
{
int a = 2;
int b = 3;
kernel_wrapper(&a, &b);
return 0;
}
还注意到.Cu编译器使用C++约定
因此,在.cu文件中需要如下内容:extern "C" void A(void)
{
.......
}
因此使用了“C”约定表面上看,您可以简单地使用
extern void fooinecuda(void)
可以在cpu.c
本身中,也可以在它包含的头中。理想情况下,报头(可能是新的)将用于gpu.cu
以及cpu.c
中,以确保交叉检查。
#ifndef __B__
#define __B__
#include "cuda.h"
#include "cuda_runtime.h"
extern "C" void kernel_wrapper(int *a, int *b);
#endif
extern "C" void A(void)
{
.......
}