6

我在尝试编译 CUDA 程序时收到以下消息:

/usr/bin/ld: 找不到 -lcudart

以前从来没有遇到过这种错误。我的 PATH 有问题吗?

这是编译命令:

gfortran -g -O2 -ffree-line-length-none -I../shared/ -o ../../bin/xspecfem3D ../../obj/spec/program_specfem3D.o ../../ obj/spec/specfem3D_par.o ../../obj/spec/PML_init.o ../../obj/spec/compute_boundary_kernel.o ../../obj/spec/compute_kernels.o ../. ./obj/spec/compute_forces_acoustic.o ../../obj/spec/compute_forces_acoustic_pot.o ../../obj/spec/compute_forces_acoustic_PML.o ../../obj/spec/compute_forces_elastic.o .. /../obj/spec/compute_forces_elastic_Dev.o ../../obj/spec/compute_forces_elastic_noDev.o ../../obj/spec/compute_forces_elastic_Dev_openmp.o ../../obj/spec/compute_add_sources_acoustic.o ../../obj/spec/compute_add_sources_elastic.o ../../obj/spec/compute_coupling_acoustic_el.o ../../obj/spec/compute_coupling_elastic_ac.o ../../obj/spec/compute_stacey_acoustic .o ../../obj/spec/compute_stacey_elastic.o ../../obj/spec/compute_gradient.o ../../obj/spec/compute_interpolated_dva.o ../../obj/spec/initialize_simulation.o ../../obj/spec/read_mesh_databases.o ../ ../obj/spec/setup_GLL_points.o ../../obj/spec/write_movie_output.o ../../obj/spec/create_color_image.o ../../obj/spec/write_seismograms.o . ./../obj/spec/write_output_ASCII.o ../../obj/spec/detect_mesh_surfaces.o ../../obj/spec/setup_movie_meshes.o ../../obj/spec/read_topography_bathymetry。 o ../../obj/spec/setup_sources_receivers.o ../../obj/spec/prepare_timerun.o ../../obj/spec/iterate_time.o ../../obj/spec/ finalize_simulation.o ../../obj/spec/save_adjoint_kernels.o ../../obj/spec/specfem3D.o ../../obj/spec/assemble_MPI_vector.o ../../obj/规格/make_gravity.o ../../obj/spec/noise_tomography.o ../../lib/libspecfem.a ../../obj/spec/check_fields_cuda.cuda.o ../../obj/spec/compute_add_sources_acoustic_cuda.cuda.o ../../obj/spec/compute_add_sources_elastic_cuda.cuda.o ../../obj/spec/compute_coupling_cuda.cuda.o ../../obj/spec/ compute_forces_acoustic_cuda.cuda.o ../../obj/spec/compute_forces_elastic_cuda.cuda.o ../../obj/spec/compute_kernels_cuda.cuda.o ../../obj/spec/compute_stacey_acoustic_cuda.cuda.o ../../obj/spec/compute_stacey_elastic_cuda.cuda.o ../../obj/spec/it_update_displacement_cuda.cuda.o ../../obj/spec/noise_tomography_cuda.cuda.o ../.. /obj/spec/prepare_mesh_constants_cuda.cuda.o ../../obj/spec/transfer_fields_cuda.cuda.o ../../obj/spec/write_seismograms_cuda.cuda.o ../../obj/spec/ save_and_compare_cpu_vs_gpu.cudacc.o ../../obj/spec/serial.o -lcuda -lcudart -lcublaso ../../obj/spec/compute_coupling_cuda.cuda.o ../../obj/spec/compute_forces_acoustic_cuda.cuda.o ../../obj/spec/compute_forces_elastic_cuda.cuda.o ../. ./obj/spec/compute_kernels_cuda.cuda.o ../../obj/spec/compute_stacey_acoustic_cuda.cuda.o ../../obj/spec/compute_stacey_elastic_cuda.cuda.o ../../obj/spec /it_update_displacement_cuda.cuda.o ../../obj/spec/noise_tomography_cuda.cuda.o ../../obj/spec/prepare_mesh_constants_cuda.cuda.o ../../obj/spec/transfer_fields_cuda.cuda。 o ../../obj/spec/write_seismograms_cuda.cuda.o ../../obj/spec/save_and_compare_cpu_vs_gpu.cudacc.o ../../obj/spec/serial.o -lcuda -lcudart -lcublaso ../../obj/spec/compute_coupling_cuda.cuda.o ../../obj/spec/compute_forces_acoustic_cuda.cuda.o ../../obj/spec/compute_forces_elastic_cuda.cuda.o ../. ./obj/spec/compute_kernels_cuda.cuda.o ../../obj/spec/compute_stacey_acoustic_cuda.cuda.o ../../obj/spec/compute_stacey_elastic_cuda.cuda.o ../../obj/spec /it_update_displacement_cuda.cuda.o ../../obj/spec/noise_tomography_cuda.cuda.o ../../obj/spec/prepare_mesh_constants_cuda.cuda.o ../../obj/spec/transfer_fields_cuda.cuda。 o ../../obj/spec/write_seismograms_cuda.cuda.o ../../obj/spec/save_and_compare_cpu_vs_gpu.cudacc.o ../../obj/spec/serial.o -lcuda -lcudart -lcublas/obj/spec/compute_stacey_acoustic_cuda.cuda.o ../../obj/spec/compute_stacey_elastic_cuda.cuda.o ../../obj/spec/it_update_displacement_cuda.cuda.o ../../obj/spec/ noise_tomography_cuda.cuda.o ../../obj/spec/prepare_mesh_constants_cuda.cuda.o ../../obj/spec/transfer_fields_cuda.cuda.o ../../obj/spec/write_seismograms_cuda.cuda.o ../../obj/spec/save_and_compare_cpu_vs_gpu.cudacc.o ../../obj/spec/serial.o -lcuda -lcudart -lcublas/obj/spec/compute_stacey_acoustic_cuda.cuda.o ../../obj/spec/compute_stacey_elastic_cuda.cuda.o ../../obj/spec/it_update_displacement_cuda.cuda.o ../../obj/spec/ noise_tomography_cuda.cuda.o ../../obj/spec/prepare_mesh_constants_cuda.cuda.o ../../obj/spec/transfer_fields_cuda.cuda.o ../../obj/spec/write_seismograms_cuda.cuda.o ../../obj/spec/save_and_compare_cpu_vs_gpu.cudacc.o ../../obj/spec/serial.o -lcuda -lcudart -lcublaso -lcuda -lcudart -lcublaso -lcuda -lcudart -lcublas

/usr/bin/ld: 找不到 -lcudart

collect2: ld 返回 1 个退出状态

编辑:

我已将链接命令更改为

gfortran -g -O2 -ffree-line-length-none -I../shared/ -L$CUDA_HOME/lib [其余如下]

我所有的 PATH 似乎都没问题,但我仍然遇到同样的错误。

编辑2:

错误是我试图编译的代码是 64 位的,所以我需要为路径提供一组不同的 .so's ,它们位于

/usr/local/cuda/lib64

现在编译运行良好,没有任何问题。

4

2 回答 2

9

您没有将 CUDA 库的位置指定给链接器,这就是链接失败的原因。nvcc被“自动”配置为查找 CUDA 运行时库组件,但如果您直接与主机编译器链接,则需要显式指定它们的位置给编译器。尝试将链接命令更改为:

gfortran -g -O2 -ffree-line-length-none -I../shared/ -L$CUDA_HOME/lib [rest follows]

whereCUDA_HOME表示安装 CUDA 工具包的路径。通常这是/usr/local/cuda在 linux 和 OS X 系统上。然后,您需要确保LD_LIBRARY_PATH包含一个条目,$CUDA_HOME/lib以便可执行文件在运行时动态加载所需的 CUDA 库。

编辑:

也看到这个

于 2012-03-09T13:44:43.400 回答
1

我修好了这个!转到您的 makefile 并将 /usr/local/cuda/ 更改为 /usr/local/cuda-7.0 (如果这是您所得到的)它对我有用

于 2015-07-19T09:10:15.677 回答