Using nvcc
I created an object file from my project with the following bash script:
nvcc -Xcompiler -std=c99 -dc src/interface.cu src/functions.cu
nvcc -dlink interface.o functions.o -o obj/link.o
In my obj
folder I get a link.o
file. I need to link this file to my Ada project using gprbuild. I can compile an Ada-Cuda project perfectly if I don't use the separate compilation mode of nvcc. But now, as I need the separate compilation mode, I have to find a way to link link.o
with the rest of the project. This is the .gpr
file:
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;
This is the error I get
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
.o
files. Would compiling with--lib
to an.a
file and then simply linking that with gprbuild solve the problem? – flyxfor Object_Dir use "obj";
and"link.o"
which may show why it's not putting them together and finding your file. The actual linker command line is probably useful too. – user_1818839Linker’Leading_Switches
. I’d be inclined to putlink.o
as the first entry inLinker’Default_Switches
. – Simon Wright