使用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发布于 2021-03-31 05:19:55
我正在做一个到动态链接库的接口,他们提供的接口是通过一个C头文件,我有一个从规范中自动生成的包;我添加了后置条件,并在包的private部分,我放了这个Linker_Options杂注,它指示链接器与动态链接库接口。-- 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,
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;https://stackoverflow.com/questions/66853892
复制相似问题