首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用gprbuild将目标文件链接到项目

使用gprbuild将目标文件链接到项目
EN

Stack Overflow用户
提问于 2021-03-29 20:05:20
回答 1查看 115关注 0票数 2

使用nvcc,我使用以下bash脚本从我的项目创建了一个对象文件:

代码语言:javascript
复制
nvcc -Xcompiler -std=c99 -dc src/interface.cu src/functions.cu
nvcc -dlink interface.o functions.o -o obj/link.o

在我的obj文件夹中,我得到了一个link.o文件。我需要使用gprbuild将此文件链接到我的Ada项目。如果我不使用nvcc的单独编译模式,我可以完美地编译Ada-Cuda项目。但现在,由于我需要单独的编译模式,我必须找到一种方法将link.o与项目的其余部分链接起来。这是.gpr文件:

代码语言:javascript
复制
project Test is
    for Languages use ("Ada");
    for Source_Dirs use ("src");
    for Object_Dir use "obj";
    for Exec_Dir use ".";

    for Main use ("main.adb");

    for Create_Missing_Dirs use "True";

    package Linker is
        for Default_Switches("Ada") use (
            "-L/usr/local/cuda/lib64",
            "-lcuda",
            "-lcudart",
            "-lcudadevrt",
            "-lstdc++",
            "-lm");

        for Leading_Switches("Ada") use (
            "link.o" -- Doesn't work
            );
    end Linker;
end Test;

这是我得到的错误

代码语言:javascript
复制
Bind
   [gprbind]      main.bexch
   [Ada]          main.ali
Link
   [link]         main.adb
/usr/local/opt/gnat-19.1-x86_64/bin/../libexec/gcc/x86_64-pc-linux-gnu/7.3.1/ld: main.o: in function `_ada_main':
main.adb:(.text+0x5): undefined reference to `bind_say_hello'
/usr/local/opt/gnat-19.1-x86_64/bin/../libexec/gcc/x86_64-pc-linux-gnu/7.3.1/ld: link.o: in function `__cudaRegisterLinkedBinary_45_tmpxft_0000404a_00000000_11_interface_cpp1_ii_f804fc64':
link.stub:(.text+0x50): undefined reference to `__fatbinwrap_45_tmpxft_0000404a_00000000_11_interface_cpp1_ii_f804fc64'
/usr/local/opt/gnat-19.1-x86_64/bin/../libexec/gcc/x86_64-pc-linux-gnu/7.3.1/ld: link.o: in function `__cudaRegisterLinkedBinary_45_tmpxft_0000404a_00000000_13_functions_cpp1_ii_e57d67fc':
link.stub:(.text+0x96): undefined reference to `__fatbinwrap_45_tmpxft_0000404a_00000000_13_functions_cpp1_ii_e57d67fc'
collect2: error: ld returned 1 exit status
gprbuild: link of main.adb failed
gprbuild: failed command was: /usr/local/opt/gnat-19.1-x86_64/bin/gcc main.o link.o b__main.o -L/usr/local/cuda/lib64 -lcuda -lcudart -lcudadevrt -lstdc++ -lm -L/home/cir_eti/Documents/test/multi_cu_file/obj/ -L/home/cir_eti/Documents/test/multi_cu_file/obj/ -L/usr/local/opt/gnat-19.1-x86_64/lib/gcc/x86_64-pc-linux-gnu/7.3.1/adalib/ -static-libgcc /usr/local/opt/gnat-19.1-x86_64/lib/gcc/x86_64-pc-linux-gnu/7.3.1/adalib/libgnat.a -ldl -Wl,-rpath-link,/usr/local/opt/gnat-19.1-x86_64/lib/gcc/x86_64-pc-linux-gnu/7.3.1//adalib -Wl,-z,origin,-rpath,/usr/local/cuda/lib64:$ORIGIN/obj:/usr/local/opt/gnat-19.1-x86_64/lib/gcc/x86_64-pc-linux-gnu/7.3.1/adalib -o /home/cir_eti/Documents/test/multi_cu_file//main
EN

回答 1

Stack Overflow用户

发布于 2021-03-31 05:19:55

我正在做一个到动态链接库的接口,他们提供的接口是通过一个C头文件,我有一个从规范中自动生成的包;我添加了后置条件,并在包的private部分,我放了这个Linker_Options杂注,它指示链接器与动态链接库接口。-- IIUC,你可以用这个来解决你的问题。

代码语言:javascript
复制
Package import_example is

    Bad_Return           : Exception;

    SUCCESS              : constant := 20007;
    NOT_INITIALIZED      : constant := 20008;
    ERROR                : constant := 20009;
    INVALID              : constant := 20010;

    Function Return_Report (Name : String; Value : unsigned ) return String is
        (Name & " should not return" & unsigned'Image(Value) & '.') with Inline;

    function item_1 return unsigned  -- some_c_header.h:249
      with Import   => True, 
      Convention    => C, 
      External_Name => "item_1",
      Post          => item_1'Result in
        SUCCESS | NOT_INITIALIZED | ERROR | INVALID
          or else raise Bad_Return with
            Return_Report("item_1", item_1'Result)
    ;

    function wait return unsigned  -- some_c_header.h:250
      with Import   => True, 
      Convention    => C, 
      External_Name => "wait",
      Post          => wait'Result in
        SUCCESS | NOT_INITIALIZED | ERROR 
          or else raise Bad_Return with
            Return_Report("wait", wait'Result)
    ;

Private
    Pragma Linker_Options( "-lsmcex" );
End import_example;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66853892

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档