謝邀。不懂android,也不懂OpenCL。但是我嘗試了解了一下你的問題。
既然你用了第三方庫,那就得查源碼了。翻開ocl 庫的源碼搜android關鍵字,很容易定位到下面代碼。
#https://github.com/cogciprocate/ocl/blob/master/ocl-interop/build.rs}elseiftarget.contains("android"){//androidletmutfile=File::create(&dest.join("egl_bindings.rs")).unwrap();Registry::new(Api::Egl,(1,4),Profile::Core,Fallbacks::All,[]).write_bindings(gl_generator::StaticGenerator,&mutfile).unwrap();println!("warning=Android support is untested! Use at your own risk, and please report any problems!");
build.rs這個文件里,看得出來它會在編譯前先根據你的target判斷出android,然后生成一個egl_bindings.rs文件,再往里寫入一些內容。
這個過程依賴 gl_generator 庫。再翻一下gl_generator庫的源碼,發現該庫主要是用來動態生成一些OpenCL FFI的Rust綁定代碼。比如android的話,就生成egl綁定 https://github.com/brendanzab/gl-rs/blob/master/gl_generator/generators/static_gen.rs
里面有人談到ocl調用OpenCL驅動的機制:Here's how it works... OpenCL uses what's called an ICD loader which just stands for installable client driver loader. All that does is act as a front end and loads every driver listed in /etc/OpenCL/vendors (on Linux). It's what lets you choose between different platforms at runtime.
When you install any OpenCL drivers for any vendor, they will automatically install an ICD and it will be hooked up correctly. This is how you should leave things by default. Importantly, when using the ICD you have to link dynamically (which is what ocl does).
A side note if you're curious: a library or binary also has the option of linking directly to a driver statically. If you wanted to do that you or I would have to configure cl-sys properly before compiling for it to work though.
也就是說,在linux上面,ocl會去固定的一個目錄去找 libOpenCL.so 。 但是他也說了,你也可以自己配置cl-sys來直接靜態鏈接驅動。
由此,可以得出一個推論:這個libOpenCL.so動態庫, 在特定的OS上面,位置是固定的。這個應該和語言無關。也就是說,不管是Rust語言還是其他語言,都應該去那個固定目錄尋找so文件。這是在Linux上面。那么安卓肯定也一樣(暫時不知道so文件默認放哪)。
也許,你碰到這個問題,也許只是安卓上面的OpenCL驅動沒有弄好? 所以我專門搜了是不是有android開發者經常找不到opencl這個動態庫。于是找到下面兩個issues:
也許你可以照這倆issues尋找下答案。
也許你需要做個軟鏈把so文件鏈到安卓的OpenCL驅動默認目錄?(評論區有人對安卓軟鏈的內容有相關補充)
希望對你有幫助。