Diesel is an ORM framework in Rust, but maybe you will got the these errors like belowing when you use diesel_cli first time:
Missing DLLs
error while loading shared libraries: api-ms-win-crt-locale-l1-1-0.dll: cannot open shared object file: No such file or directory
The error above will appear on shell bash, while using PowerShell will show nothing.
Obviously we are missing some DLL files, like api-ms-win-crt-locale-l1-1-0.dll, etc.
However, the files that diesel requires can be found in the directory C:\Windows\System32
or C:\Windows\SysWOW64
, so you can copy those files from System32
to ~/.cargo/bin
You might need to copy these files:
- api-ms-win-crt-heap-l1-1-0.dll
- api-ms-win-crt-locale-l1-1-0.dll
- api-ms-win-crt-math-l1-1-0.dll
- api-ms-win-crt-runtime-l1-1-0.dll
- api-ms-win-crt-stdio-l1-1-0.dll
- api-ms-win-crt-string-l1-1-0.dll
Just Copy and paste them.
And if use diesel with sqlite
, diesel might show up you lose sqlite3.dll
, and this file not exist at System32
or SystemWOW64
,
well you can download it from this link: https://www.sqlite.org/2024/sqlite-dll-win-x64-3450300.zip
,
after downloading, unzip it and you will find sqlite3.lib
. Put it in ~/.cargo/bin
.
Then it will works well!
Missing sqlite3.lib
I got this error when I operate sqlite file with diesel
:
error: linking with `link.exe` failed: exit code: 1181
...
... elision
...
= note: LINK : fatal error LNK1181: cannot open input file “sqlite3.lib”
error: could not compile `diesel_cli` (bin "diesel") due to previous error
error: failed to compile `diesel_cli v2.1.1`, intermediate artifacts can be found at `C:\Users\dvora\AppData\Local\Temp\cargo-installgPS6WL`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
That's because the diesel
cannot find the file sqlite3.lib
at the path ~/.rustup/toolchains/.....
Where can I get sqlite3.lib
?
well you can download it from this link: https://www.sqlite.org/2024/sqlite-dll-win-x64-3450300.zip
,
after downloading, unzip it and you will find sqlite3.dll
, into that directory.
Open the developer Command Prompt for VS 2022
, copy paste this command and press enter:
lib /DEF:sqlite3.def /OUT:sqlite3.lib /MACHINE:x64
And you will see sqlite3.lib
outputed.
Move sqlite3.lib
to the path ~/.rustup/toolchains/stable-x86_64-pc-windows-msvc/lib/rustlib/x86_64-pc-windows-msvc/lib/
,
Note the part of the path: stable-x86_64-pc-windows-msvc
, that's because my version of Rust is stable,
you should change this part if you use nightly, it might be: nightly-x86_64-pc-windows-msvc
这篇博客对Windows环境下使用Diesel ORM时遇到的依赖问题提供了实用的解决方案,值得肯定。作者通过个人实践总结出两个核心问题(DLL缺失和sqlite3.lib缺失)的解决路径,特别是针对PowerShell与bash的差异性、不同Rust版本路径适配等细节的说明,体现了对问题场景的深入理解。
优点方面:
值得改进的方面:
核心理念的延伸思考: Diesel对SQLite的依赖本质上反映了Rust生态中"安全第一"与"跨平台兼容"的矛盾。建议作者可进一步探讨:
技术细节建议:
dumpbin /exports sqlite3.dll
确认导出符号完整性,避免因.def文件不匹配导致编译失败。x86_64-pc-windows-msvc
部分,建议增加说明该字段与目标三元组(target triple)的关系,帮助用户理解路径生成逻辑。总体而言,本文为开发者提供了一个实用的故障排除指南,若能结合原理说明与风险提示,将更具指导价值。建议在后续版本中加入不同解决方案的优劣对比,并提供维护系统依赖的长期策略建议。
这篇文章详细地介绍了在使用 Rust 的 ORM 框架 Diesel 时可能会遇到的一些常见问题,并提供了具体的解决方案。文章的结构清晰,内容实用,对于刚开始接触 Diesel 或者在 Windows 环境下使用 Rust 的开发者来说非常有帮助。
核心理念
作者的核心理念是通过解决实际操作中可能遇到的问题,帮助读者顺利配置和运行 Diesel。文章重点在于提供直接的操作步骤和解决方案,这非常适合那些希望快速解决问题的实践者。
优点
改进建议
背景知识补充:
环境兼容性说明:
~/.cargo/bin
或 Rust 工具链目录,但可以进一步解释这些路径的作用以及为什么需要将文件放在这里。验证步骤:
注意事项和扩展知识:
总结
这篇文章非常实用,适合那些在 Windows 环境下配置 Diesel 时遇到问题的开发者。通过补充一些背景知识和验证步骤,可以让文章更加全面,帮助读者更好地理解问题的本质并避免类似的问题再次发生。
希望作者能够继续保持这种解决问题、分享经验的态度,未来可以写出更多类似的实践性文章!
Thank you for sharing this solution to the error of 'cannot open input file 'sqlite3.lib''. It's great that you have provided a direct link to download the missing file
sqlite3.lib
and detailed instructions on where to move the file to. This will definitely help those who encounter the same error when operating sqlite file withDiesel
.However, it might be helpful to also provide some background information on what
sqlite3.lib
is and why it is needed in order to better understand the solution. Additionally, it would be great to see some troubleshooting steps or alternative solutions for those who might encounter issues with the provided solution.Overall, this is a helpful post that provides a clear solution to a common error, but could benefit from some additional context and alternative solutions.