make test results in linker error cannot find OpenCL library
I'm running pop 22.04 with rust nightly. I installed opencl using the following on pop 22.04:
wget -O '/tmp/rocm.gpg.key' 'https://repo.radeon.com/rocm/rocm.gpg.key'
sudo mv '/tmp/rocm.gpg.key' '/etc/apt/trusted.gpg.d/rocm.asc'
sync
echo 'deb https://repo.radeon.com/rocm/apt/latest/ ubuntu main' | sudo tee '/etc/apt/sources.list.d/rocm.list' > '/dev/null' && cat '/etc/apt/sources.list.d/rocm.list'
sudo apt update
sudo apt install rocm-opencl rocm-opencl-dev
sudo usermod --append --groups 'render,video' davidm
reboot
make check worked correctly.
When I ran make test I got the following error:
warning: `blaze-rs` (lib) generated 1 warning
error: linking with `cc` failed: exit status: 1
|
= note: "cc" "-m64" "/tmp/rustcYB6OSv/symbols.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.15cy7bkgix8rtwg3.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.1d14oo4kxedhit6o.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.1dfj0s8tnfj66n11.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.1jzbg4vxwmn1tl3v.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.1qhsxzaro8n1w99a.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.1tdk9eemfhn2zcg.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.1xn9autc40enwghi.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.1zsf2gwqy4mk93jj.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.24zi57ojr1d3znz5.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.2rknx43j1k2w92mm.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.33cj9rdy9nydjddd.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.3o7i5gto1qowp5le.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.3oq2eyd3cl8b746h.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.3pro4muk0al00hzt.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.43z7q5wadfeeajuv.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.46h448z5ts6mxl1n.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.4gew5rp4owhe4y30.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.4hp40b0uhznpzxsc.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.4lfvys2pukeu5qxb.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.4urkuwfmhbm7w3dx.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.74uzz8wymtnyi7h.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.kaudi0fmqii0nc2.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.mptv03y5670yfj5.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.noeicez4c5bdkfn.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.y80h7y7ic69veke.rcgu.o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd.vm4eld2qok6v4gp.rcgu.o" "-Wl,--as-needed" "-L" "/home/davidm/blaze/target/debug/deps" "-L" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libtest-da913cdf5d7548fa.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgetopts-5214be050813988f.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode_width-545547c7a91a5f54.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_std-9601d44b3c2bcb0c.rlib" "/home/davidm/blaze/target/debug/deps/libblaze_rs-6d10004028fd0a39.rlib" "/home/davidm/blaze/target/debug/deps/libbox_iter-79d13ebcbdf9c843.rlib" "/home/davidm/blaze/target/debug/deps/libbitflags-05dfd5b5d1225bed.rlib" "/home/davidm/blaze/target/debug/deps/libcfg_if-90e3626e3c41eec3.rlib" "/home/davidm/blaze/target/debug/deps/libopencl_sys-200821ad1c61cc9a.rlib" "/home/davidm/blaze/target/debug/deps/liblibc-e1c27bc548d6aea8.rlib" "/home/davidm/blaze/target/debug/deps/libonce_cell-1f5534b23b172a64.rlib" "-Wl,--start-group" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-4393e7d07259b8a4.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-e13cbb326bcd01a4.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-13ac6af5403a52c8.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-a7b8febdd2acb289.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-343513f0726f71ed.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-8f833d900bfb98aa.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-e97a7960ca6216c8.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-683fb35093a61fcc.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-f943c2d34bd4b56d.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-72ce2aaa649404e0.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-ac5d08ad5339e92e.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-dacfda262d5656fb.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-e2056a834ba0712c.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-a60649c148c6e2db.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-3e961d059b9bcde7.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-20f26f875d0170e2.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-522518611024dce5.rlib" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-05898138a596088a.rlib" "-Wl,--end-group" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-5b83a1df856cf582.rlib" "-Wl,-Bdynamic" "-lOpenCL" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/davidm/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/davidm/blaze/target/debug/deps/mmul-a5f88daec8c33fdd" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
= note: /usr/bin/ld: cannot find -lOpenCL: No such file or directory
collect2: error: ld returned 1 exit status
I also checked to confirm OpenCL libraries have been installed. There are more of them than I can shake a stick at! Shouldn't the above build have /usr/lib/x86_64-linux-gnu/ as part of its linker search path at the very least?
/usr/lib/x86_64-linux-gnu/libOpenCL.so.1.0.0
/usr/lib/x86_64-linux-gnu/libOpenCL.so.1
/opt/rocm-5.2.0/opencl/lib/libOpenCL.so
/opt/rocm-5.2.0/opencl/lib/libOpenCL.so.1
/opt/rocm-5.2.0/opencl/lib/libOpenCL.so.1.2
/opt/rocm-5.2.0/lib/libOpenCL.so
/opt/rocm-5.2.0/lib/libOpenCL.so.1
/opt/rocm-5.2.0/lib/libOpenCL.so.1.2
/home/davidm/.local/share/flatpak/.removed/org.freedesktop.Platform-e5aff027f1cfc1b950d476dab5159628f077a4ca114e87160a123df9cce700bf/files/lib/x86_64-linux-gnu/libOpenCL.so.1.0.0
/home/davidm/.local/share/flatpak/.removed/org.freedesktop.Platform-e5aff027f1cfc1b950d476dab5159628f077a4ca114e87160a123df9cce700bf/files/lib/x86_64-linux-gnu/libOpenCL.so.1
/home/davidm/.local/share/flatpak/runtime/org.gnome.Platform/x86_64/41/07e2f19d660a4bf5520857f2eea3aa7005d0e320b2ee5ec7c02a5ea95d2123a3/files/lib/x86_64-linux-gnu/libOpenCL.so.1.0.0
/home/davidm/.local/share/flatpak/runtime/org.gnome.Platform/x86_64/41/07e2f19d660a4bf5520857f2eea3aa7005d0e320b2ee5ec7c02a5ea95d2123a3/files/lib/x86_64-linux-gnu/libOpenCL.so.1
/home/davidm/.local/share/flatpak/runtime/org.gnome.Platform/x86_64/42/95efaa2378b7fe76734f58eae5a52bb66d0e73bcded62470e97159cb15e93315/files/lib/x86_64-linux-gnu/libOpenCL.so.1.0.0
/home/davidm/.local/share/flatpak/runtime/org.gnome.Platform/x86_64/42/95efaa2378b7fe76734f58eae5a52bb66d0e73bcded62470e97159cb15e93315/files/lib/x86_64-linux-gnu/libOpenCL.so.1
/home/davidm/.local/share/flatpak/runtime/org.kde.Platform/x86_64/5.15-21.08/497a0d244beeb1308837e356ec9a39dfdaf23d9de18998aeaaa05f171f0415a2/files/lib/x86_64-linux-gnu/libOpenCL.so.1.0.0
/home/davidm/.local/share/flatpak/runtime/org.kde.Platform/x86_64/5.15-21.08/497a0d244beeb1308837e356ec9a39dfdaf23d9de18998aeaaa05f171f0415a2/files/lib/x86_64-linux-gnu/libOpenCL.so.1
/home/davidm/.local/share/flatpak/runtime/org.freedesktop.Platform/x86_64/21.08/c7252386179c4c1ecf5d93bdaec6ca82852dddfdae7112b5c3177f7424c4a928/files/lib/x86_64-linux-gnu/libOpenCL.so.1.0.0
/home/davidm/.local/share/flatpak/runtime/org.freedesktop.Platform/x86_64/21.08/c7252386179c4c1ecf5d93bdaec6ca82852dddfdae7112b5c3177f7424c4a928/files/lib/x86_64-linux-gnu/libOpenCL.so.1
The one OpenCL library that blaze refers to doesn't use version numbers in the prefix so I made sure the symbolic link's name has no versions in it, just libOpenCL.so
Create a new link in that requested directory:
cd /usr/lib/x86_64-linux-gnu
ln -s -T /opt/rocm-5.2.0/lib/libOpenCL.so.1.2 libOpenCL.so
Listing the new shared lib:
ls -lht libOpenCL.so
lrwxrwxrwx 1 root root 36 Aug 23 14:41 libOpenCL.so -> /opt/rocm-5.2.0/lib/libOpenCL.so.1.2
I also tweaked the Makefile a bit to add the linker search path:
cat Makefile |grep RUSTFLAGS
RUSTFLAGS='-L /usr/lib/x86_64-linux-gnu' cargo check --no-default-features
RUSTFLAGS='-L /usr/lib/x86_64-linux-gnu' cargo check --all-features
RUSTFLAGS='-L /usr/lib/x86_64-linux-gnu' cargo test --no-default-features
RUSTFLAGS='-L /usr/lib/x86_64-linux-gnu' cargo test --all-features
make test links successfully and spews out the following test output:
Running unittests src/lib.rs (target/debug/deps/blaze_rs-ffa00b9b7d034f8a)
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running tests/error_probing.rs (target/debug/deps/error_probing-c717882ed61475a4)
running 1 test
test invalid_raw ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running tests/mmul.rs (target/debug/deps/mmul-a5f88daec8c33fdd)
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running tests/rect.rs (target/debug/deps/rect-5e6f7515e6a228d4)
running 6 tests
test boxed ... ok
test col_iter ... ok
test col_major ... ok
test row_iter ... ok
test transpose ... ok
test zeroed ... ok
test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running tests/rng.rs (target/debug/deps/rng-08758b0598f0bbcd)
running 1 test
test main ... FAILED
failures:
---- main stdout ----
thread 'main' panicked at 'DeviceNotFound
disabled backtrace', src/core/device.rs:14:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
main
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.53s
error: test failed, to rerun pass '--test rng'
make: *** [Makefile:10: test] Error 101
make checkworked correctly.
make check is used to check if the project compiles with all (or at least most) feature combinations.
However, cargo check (which is what's used for make check under the hood) doesn't try to link any libraries (I guess that's because it's not really compiling the code), so it doesn't detect linking errors. cargo test does actually compile the code (obviously), so it does catch linking errors.
As for this, the following tests:
running 6 tests test boxed ... ok test col_iter ... ok test col_major ... ok test row_iter ... ok test transpose ... ok test zeroed ... ok
Are for the Rect2D type, whose implementation is fully on the CPU, so those should (pretty much) always work.
As for the main test from rng, it requires OpenCL 3.0 or higher, so it should probably be marked as to only run when the cl3 feature is active.