与海湾合作委员会链接CUDA静态或共享库未定义引用错误 [英] undefined reference error for linking CUDA static or shared library with gcc

查看:285
本文介绍了与海湾合作委员会链接CUDA静态或共享库未定义引用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gcc和CUDA问题

我编了一CUDA共享库,但不能与使用它的主程序链接。我编译主程序与海湾合作委员会。

在code:

simplemain.c

 的#include<&stdio.h中GT;
    #包括LT&;&stdlib.h中GT;    无效fcudadriver();    诠释的main()
    {
      的printf(主\\ n);
      fcudadriver();
      返回0;
    }

test.cu

  __global__无效fcuda()
    {
    }    无效fcudadriver()
    {
      fcuda&所述;&所述;&所述; 1,1 GT;>>();
    }

我编译test.cu为 - >它的工作原理

  NVCC --compiler选项-fPIC-o libtest.so --shared test.cu

我编译simplemain.c为--->它给出了错误:(

  GCC simplemain.c -L。 -ltest
    /tmp/ccHnB4Vh.o:simplemain.c:function主:错误:未定义参考fcudadriver
    collect2:劳工处返回1退出状态


解决方案

尝试使用G ++而不是GCC。 NVCC使用C ++风格的链接约定。 (你并不需要重命名的文件。)

另外,如果你必须使用gcc,preface你的无效fcudadriver()函数的定义是这样的:

 的externC无效fcudadriver()

gcc and CUDA question

Hi,

I have compiled a CUDA shared library but can't link it with the main program that uses it. I am compiling the main program with gcc.

The code:

simplemain.c

    #include <stdio.h>
    #include <stdlib.h>



    void fcudadriver();

    int main()
    {
      printf("Main \n");
      fcudadriver();
      return 0;
    }

test.cu

    __global__ void fcuda()
    {
    }

    void fcudadriver()
    {
      fcuda<<<1,1>>>();
    }

I compile test.cu as --> It works

    nvcc --compiler-options '-fPIC' -o libtest.so --shared test.cu

I compile simplemain.c as ---> It gives error :(

    gcc simplemain.c -L. -ltest
    /tmp/ccHnB4Vh.o:simplemain.c:function main: error: undefined reference to 'fcudadriver'
    collect2: ld returned 1 exit status

解决方案

try using g++ instead of gcc. nvcc uses c++ style linking conventions. (You don't need to rename any files.)

alternatively, if you must use gcc, preface your void fcudadriver() function definition like this:

extern "C" void fcudadriver()

这篇关于与海湾合作委员会链接CUDA静态或共享库未定义引用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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