Building the tk crate on Windows
I've been continuing my study of Rust and decided to build another GUI application. My first app used slint and wanted to try something new this time. There's a few gui options available and today I thought I would try the tk crate which are bindings to the Tk graphical user interface toolkit. From what I've read it's the standard GUI toolkit for Python.
As noted in the tk crate tutorial, I first installed ActiveTCL. I then created a new project with cargo new tk-testing
. I then added the tk crate with cargo add tk
. I then copied the "Hello World" Example into my main.rs file and tried to run it with cargo run
. I then got some errors similar to the following (I'm on Windows 10 by the way)...
could not find Tcl_HideCommand in crate `clib`
cannot find function, tuple struct or tuple variant `Tcl_IsSafe` in crate `clib`
Looking at the issue tracker for clib and tk, I found these tickets [1] [2] which helped me realize that I need to install the clang compiler. I already had Visual Studio C++ Development Tools installed, but I had to modify the installation so I also installed the "C++ Clang Compiler for Windows". I then did a cargo clean
followed by another cargo run
and I got this error...
error: failed to run custom build command for `clib v0.2.4`
Caused by:
process didn't exit successfully: `C:\Users\Dominick\Documents\backup\projects\rust\ticket-tracker\target\debug\build\clib-670e397403d141a3\build-script-build` (exit code: 101)
--- stdout
cargo:rerun-if-changed=C:\Users\Dominick\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tcl-0.1.9\Cargo.toml
cargo:rerun-if-env-changed=TCL86_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-pc-windows-msvc
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_pc_windows_msvc
-snip-
--- stderr
{
"C:\\Users\\Dominick\\Documents\\backup\\projects\\rust\\ticket-tracker\\target\\debug\\build\\tk-e9e85496aed524f4",
"C:\\Users\\Dominick\\Documents\\backup\\projects\\rust\\ticket-tracker\\target\\debug\\build\\libc-cfe0f9789a241e24\\invoked.timestamp",
-snip-
Unable to find libclang: "couldn't find any valid shared libraries matching: ['clang.dll', 'libclang.dll'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"
That's progress. So I then set the "LIBCLANG_PATH" environment variable to point to the clang.exe executable. To find clang, I searched in the "C:/Program Files" directory for "clang". Mine was located in "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin". After updating the ENV variable and restarting my editor, I did a cargo clean
followed by cargo run
, and I was able to build and run the hello world example!