我正在尝试使用红须构建基本的cargo build
示例,但是我得到了错误:
error: linking with `cc` failed: exit code: 1
|
/*
* 提示:该行代码过长,系统自动注释不进行高亮。一键复制会移除系统注释
* = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.114qu21cmyxgm5vs.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.130tmtat0zrjo2g1.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.15brzeh653yx84a6.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.17jbii9zijh37jjg.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.18yjk17cfr819y8w.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.1a0fah2mumbeaumw.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.1cimqn8d9gj5vok.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.1db5rh3i9dt4e3lz.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.1gb5shwuid6pzxod.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.1o5y5zwtfv93r6og.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.1xo68oma4zrk4eg4.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.1xzbdr8svhuclhy7.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.241ihdeu7wf4ipqt.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.2c51ho6oiwcqjvv1.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.2chr72f12t8fd9gf.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.2yfh41y5eihwhaa8.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.3a5a41ou0q54qbzq.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.3oeokeiewje0j557.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.3pz55wtb7i2gf86g.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.3vgxaa6gtfuqmmez.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.42liv0986ykss7ps.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.48yahxkfhp06pfgy.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.49pugvri298rimvb.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.4m32ecgz8eri0qre.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.4nzsvwud929q7bn.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.4q5cfvh88socnc12.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.4vkk6p37e0vjleo2.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.5dw7cr2qjxl8mqfg.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.8l6kkr142tyxd9t.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.jlt8brtgsf99ub7.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.onbelurnvv1gxad.rcgu.o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.yte3xk9q6l3o5n3.rcgu.o" "-o" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0" "/home/jonathan/Projects/rust_test/target/debug/deps/rust_test-3c102f2d126c37d0.46jz4cvystllzxz0.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/home/jonathan/Projects/rust_test/target/debug/deps" "-L" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/jonathan/Projects/rust_test/target/debug/deps/librustacuda-c1901c84639ee5ec.rlib" "/home/jonathan/Projects/rust_test/target/debug/deps/librustacuda_core-f54c47e82bdeb5e8.rlib" "/home/jonathan/Projects/rust_test/target/debug/deps/libcuda_sys-7fc293ad3a914650.rlib" "/home/jonathan/Projects/rust_test/target/debug/deps/libbitflags-1324f5a1f5de34d5.rlib" "-Wl,--start-group" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-4a76ff35a356aedf.rlib" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-e11c7b3b3225afe2.rlib" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace-13217ede3d276f16.rlib" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-621a9ee22da6caa1.rlib" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-546c844e8071bbeb.rlib" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-be9569e4d599746f.rlib" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-47d8845cef2a3bc5.rlib" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-017511bce73a530c.rlib" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-be7979c57a08057b.rlib" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-d6459c4f0817c67c.rlib" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-580035dd98451925.rlib" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-aee5c24fff305dea.rlib" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-8a55a4098920125a.rlib" "-Wl,--end-group" "/home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-9fc4b5be2ba5cc19.rlib" "-Wl,-Bdynamic" "-lcuda" "-lcudart" "-lcublas" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"
*/
= note: /usr/bin/ld: cannot find -lcudart
collect2: error: ld returned 1 exit status
我认为这与安装的这一部分有关:
export CUDA_LIBRARY_PATH="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\lib\x64"
我使用的是Linux,因此不能使用这个。我最好的猜测是,Linux上的等价物是:
export CUDA_LIBRARY_PATH="/usr/local/cuda-10.2/lib64/"
我也尝试过:
export CUDA_LIBRARY_PATH="/usr/local/cuda-10.2/"
正如它所建议的那样:
export LIBRARY_PATH="/usr/local/cuda-10.2/lib64/"
export LIBRARY_PATH="/usr/local/cuda-10.2/"
所有这些似乎都产生了同样的问题。
我真的不知道这是什么错误,很少单独如何纠正它。
我的最小可重现性例子。它要求你安装了数据自动化系统。虽然您可以在Windows上运行这个程序,但我不认为您可以复制相同的错误。
发布于 2020-01-29 18:33:33
铁锈中使用数据自动化系统的逐步指南(在Ubuntu 19.04上测试)
安装CUDA:
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo cp cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget http://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
sudo apt-key add /var/cuda-repo-10-2-local-10.2.89-440.33.01/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda
reboot
在重新启动后验证它是否成功:
nvidia-smi
验证驱动程序版本:
cat /proc/driver/nvidia/version
输出(可能因您而异):
NVRM version: NVIDIA UNIX x86_64 Kernel Module 390.129 Mon Jul 22 21:10:21 PDT 2019
GCC version: gcc version 8.3.0 (Ubuntu 8.3.0-6ubuntu1)
版本:
nvcc --version
输出(可能因您而异):
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89
添加到启动文件末尾(例如/etc/bash.bashrc
):
export PATH=$PATH:/usr/local/cuda-10.2/bin
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}/usr/local/cuda-10.2/targets/x86_64-linux/lib
export CUDA_LIBRARY_PATH=/usr/local/cuda-10.2/targets/x86_64-linux/lib
# Verify:
code /etc/bash.bashrc
code /etc/environment
code ~/.profile
运行:
echo $PATH
# Output:
# ...:/usr/local/cuda-10.2/bin
echo $LD_LIBRARY_PATH
# Output:
# /usr/local/cuda-10.2/targets/x86_64-linux/lib:/home/wasmup/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/usr/lib/x86_64-linux-musl
echo $CUDA_LIBRARY_PATH
# output:
# /usr/local/cuda-10.2/targets/x86_64-linux/lib
然后创建一个新的锈蚀项目(例如cuda101
)并添加依赖关系:
cargo new cuda101
cd cuda101
cargo search rustacuda >> Cargo.toml
因此,Cargo.toml
文件dependencies
如下所示:
[dependencies]
rustacuda = "0.1.1" # CUDA Driver API Wrapper
rustacuda_core = "0.1.1" # Minimal kernel-support crate for Rustacuda
rustacuda_derive = "0.1.1" # Custom Derive Macro for RustaCUDA
从resources/add.ptx
存储库下载RustaCUDA文件,并将其放在应用程序的资源目录中:
mkdir resources
cp ../RustaCUDA/resources/add.ptx resources/add.ptx
运行:
cargo run
# Or:
cargo run --release
输出:
Sum is 30
main.rs
文件:
#[macro_use]
extern crate rustacuda;
use rustacuda::memory::DeviceBox;
use rustacuda::prelude::*;
use std::error::Error;
use std::ffi::CString;
fn main() -> Result<(), Box<dyn Error>> {
// Initialize the CUDA API
rustacuda::init(CudaFlags::empty())?;
// Get the first device
let device = Device::get_device(0)?;
// Create a context associated to this device
let _context =
Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device)?;
// Load the module containing the function we want to call
let module_data = CString::new(include_str!("../resources/add.ptx"))?;
let module = Module::load_from_string(&module_data)?;
// Create a stream to submit work to
let stream = Stream::new(StreamFlags::NON_BLOCKING, None)?;
// Allocate space on the device and copy numbers to it.
let mut x = DeviceBox::new(&10.0f32)?;
let mut y = DeviceBox::new(&20.0f32)?;
let mut result = DeviceBox::new(&0.0f32)?;
// Launching kernels is unsafe since Rust can't enforce safety - think of kernel launches
// as a foreign-function call. In this case, it is - this kernel is written in CUDA C.
unsafe {
// Launch the `sum` function with one block containing one thread on the given stream.
launch!(module.sum<<<1, 1, 0, stream>>>(
x.as_device_ptr(),
y.as_device_ptr(),
result.as_device_ptr(),
1 // Length
))?;
}
// The kernel launch is asynchronous, so we wait for the kernel to finish executing
stream.synchronize()?;
// Copy the result back to the host
let mut result_host = 0.0f32;
result.copy_to(&mut result_host)?;
println!("Sum is {}", result_host);
Ok(())
}
如果出现错误,/usr/bin/ld: cannot find -lcudart
在当前目录中创建一个软链接:
ln -s /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudart.so.10.2.89 cudart
验证新的软链接:
ls -l /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudart.so.10.2.89 cudart
发布于 2020-01-29 02:37:31
查看错误列表的这一部分:
note: /usr/bin/ld: cannot find -lcudart
因此,ld无法找到它需要的库,您需要告诉它应该在哪里查找它。可以使用-L参数向链接器提供库的路径。例如,在我的Linux系统中,当我想使用Boost::Pythonv1.70编译我的C++程序时,我使用以下命令:
g++ <cpp_flags> <include_paths> -L/home/roger/boost-1.70.0/install-dir/lib -c <source_files> -lboost_python-py36
g++ <cpp_flags> -o <output_program> <object_files>
https://stackoverflow.com/questions/59959703
复制相似问题