如何解决使用 gprbuild 将目标文件链接到项目
使用 nvcc
,我使用以下 bash 脚本从我的项目创建了一个目标文件:
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
文件:
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;
这是我得到的错误
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
解决方法
我正在做一个 DLL 的接口,他们提供的接口是通过 C 头文件,我有一个从规范中自动生成的包;我正在添加后置条件,并且在包的 private
部分,我放置了这个 Linker_Options
pragma,它指示链接器与 DLL 进行交互。 -- IIUC,你可以用它来解决你的问题。
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,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;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。