# Error: Error calling dlltool 'dlltool.exe': program not found

**URL:** <https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236>\
**Category:** help\
**Created:** [January 17, 2025, 11:57pm UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236 "2025-01-17T23:57:00Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![MOCKBA](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/mockba/32/41423_2.png) [@MOCKBA](https://users.rust-lang.org/u/MOCKBA)\
**Post date:** [January 17, 2025, 11:57pm UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/1 "2025-01-17T23:57:01Z")

</div>

I am trying to write a simple program using Windows API like that:

```rust
extern crate windows_link;

fn main() {
    windows_link::link!("kernel32.dll" "system" fn SetLastError(code: u32));
    windows_link::link!("kernel32.dll" "system" fn GetLastError() -> u32);
    
    unsafe {
        SetLastError(1234);
        assert_eq!(GetLastError(), 1234);
    }
}

```

However I am getting:

error: Error calling dlltool 'dlltool.exe': program not found

error: aborting due to 1 previous error

Rust programs not using Windows API are compiled and run fine.

---

<div class="post-metadata">

**Author:** ![nerditation](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@nerditation](https://users.rust-lang.org/u/nerditation)\
**Post date:** [January 18, 2025, 12:17am UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/2 "2025-01-18T00:17:29Z")

</div>

is there any reason you are using `windows-link` insead of `windows-targets`?

are you using the `-windows-gnu` toolchain? make sure the `rust-mingw` component is installed, it should contain a `dlltool`.

---

<div class="post-metadata">

**Author:** ![MOCKBA](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/mockba/32/41423_2.png) [@MOCKBA](https://users.rust-lang.org/u/MOCKBA)\
**Post date:** [January 18, 2025, 12:37am UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/3 "2025-01-18T00:37:51Z")

</div>

[quote="nerditation, post:2, topic:124236"]  
are you using the `-windows-gnu` toolchain?  
[/quote] Yes, I am. Otherwise I am getting a link error.

> [@nerditation](#):
>
> is there any reason you are using `windows-link` insead of `windows-targets`?

There is no any reason. My intention was I just installed Rust and hoped that developed programs will work out of the box.

---

<div class="post-metadata">

**Author:** ![MOCKBA](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/mockba/32/41423_2.png) [@MOCKBA](https://users.rust-lang.org/u/MOCKBA)\
**Post date:** [January 18, 2025, 1:14am UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/4 "2025-01-18T01:14:34Z")

</div>

I tried targets with another problem:

```rust
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
 --> test.rs:1:1
  |
1 | extern crate windows_targets;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information

error: aborting due to 1 previous error

```

---

<div class="post-metadata">

**Author:** ![nerditation](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@nerditation](https://users.rust-lang.org/u/nerditation)\
**Post date:** [January 18, 2025, 1:15am UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/5 "2025-01-18T01:15:12Z")

</div>

> [@MOCKBA](#):
>
> Otherwise I am getting a link error.

may I guess you didn't install visual C++ build tools? if you dont want to do that, the `-windows-msvc` toolchain will not work.

the `-windows-gnu` toolchain is self-contained, in that you don't need external tools for "pure rust" programs. (as soon as you want to use FFI libraries, you still need to install `mingw` gcc).

> [@MOCKBA](#):
>
> My intention was I just installed Rust and hoped that developed programs will work out of the box.

for a better OOB experience with the Windows API, you should use the `windows` or `windows-sys` crate. the `windows-link` crate is very low level, and it uses unstable (last time I checked) features of rust, so it's not really suitable for new learners.

---

<div class="post-metadata">

**Author:** ![nerditation](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@nerditation](https://users.rust-lang.org/u/nerditation)\
**Post date:** [January 18, 2025, 1:17am UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/6 "2025-01-18T01:17:49Z")

</div>

> [@MOCKBA](#):
>
> `extern crate windows_targets;`

did you add `windows-targets` to `Cargo.toml` as a dependency?

---

<div class="post-metadata">

**Author:** ![MOCKBA](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/mockba/32/41423_2.png) [@MOCKBA](https://users.rust-lang.org/u/MOCKBA)\
**Post date:** [January 18, 2025, 2:26am UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/7 "2025-01-18T02:26:58Z")

</div>

I do not use Cargo, just rustc. I think you right, I have to install some development tool beyond just Rust. Actually I switched to the gnu target, because Rust couldn't find link.exe. Thank you for the help.

---

<div class="post-metadata">

**Author:** ![nerditation](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@nerditation](https://users.rust-lang.org/u/nerditation)\
**Post date:** [January 18, 2025, 3:21am UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/8 "2025-01-18T03:21:01Z")

</div>

> [@MOCKBA](#):
>
> I do not use Cargo, just rustc.

for better OOB experience, I' suggest to stick with `cargo` (unless you are author of build tools who want to integrate `rustc` to your tool.)

`cargo` is not only a build tool, but also a package manager. it gives you smooth experience to use libraries from `crates.io`, which is the default registry of `cargo`, but you can use custom registries if needed.

with `cargo`, using third party crates is almost as easy as using the standard library. using your original example:

```plaintext
> cargo new hello
> cd hello
> cargo add windows-sys --features Win32_Foundation
> notepad src/main.rs

```

```rust
// main.rs
use windows_sys::Win32::Foundation::{GetLastError, SetLastError};
fn main() {
    unsafe {
        SetLastError(1234);
        assert_eq!(GetLastError(), 1234);
    }
}

```

```plaintext
> cargo run

```

there's a small inconvenience when it comes to the `windows`/`windows-sys` crates, namely, you must enable subsets of APIs explicitly using features, and there's a ton of them. but at least, microsoft provides a search interface:

> **[Rust for Windows - Features](https://microsoft.github.io/windows-rs/features/)**
>
> Search for items in the windows-rs crate and instantly retrieve the required features for cargo.toml.

because the Windows API set is so large, even the `windows-sys` crate, which contains only declarations of FFI types and function signatures, and linkage information, the compile time would be unmanageable if all the APIs are enabled unconditionally. bummer, but it is what it is. it's a trade off for the completeness of the full Windows API set.

* * *

using `rustc` directly _is_ possible, but it won't be as easy, unless your code is very simple, e.g., only uses the standard library (i.e. `std`, `alloc`, `core`). anything beyond that is rather involved, e.g., you can pass the `--verbose` flag to see the the full command line of how `rustc` is invoked.

notably, direct access of OS APIs (bypasisng the standard library) needs to use third party crates, e.g. the `libc` crate, or even lower level, like `nix` for Posix systems, `windows-sys` for Windows.

---

<div class="post-metadata">

**Author:** ![MOCKBA](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/mockba/32/41423_2.png) [@MOCKBA](https://users.rust-lang.org/u/MOCKBA)\
**Post date:** [January 18, 2025, 4:18am UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/9 "2025-01-18T04:18:58Z")

</div>

I really surprised that Rust for Windows so complicated. Last time I used Turbo Pascal for Windows and somehow all mechanisms were hidden for me. My programs just worked. However if I use Rust I have to use Cargo and crates. It's a bit unusual, but it is the price for progress.

---

<div class="post-metadata">

**Author:** ![nerditation](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@nerditation](https://users.rust-lang.org/u/nerditation)\
**Post date:** [January 18, 2025, 5:05am UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/10 "2025-01-18T05:05:37Z")

</div>

> [@MOCKBA](#):
>
> Last time I used Turbo Pascal

good old days.

---

<div class="post-metadata">

**Author:** ![Kyllingene](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/kyllingene/32/33899_2.png) [@Kyllingene](https://users.rust-lang.org/u/Kyllingene)\
**Post date:** [January 18, 2025, 6:16am UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/11 "2025-01-18T06:16:05Z")

</div>

FWIW, Cargo is the recommended way in all the documentation, and so ubiquitous that the vast majority of material assumes you're using it. Using plain rustc is what I'd consider unusual, like if you didn't use a build system for C#.

---

<div class="post-metadata">

**Author:** ![MOCKBA](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/mockba/32/41423_2.png) [@MOCKBA](https://users.rust-lang.org/u/MOCKBA)\
**Post date:** [January 18, 2025, 6:44am UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/12 "2025-01-18T06:44:49Z")

</div>

Cargo is just a tool to generate arguments for rustc.

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/bjorn3/32/5255_2.png) [@bjorn3](https://users.rust-lang.org/u/bjorn3)\
**Post date:** [January 18, 2025, 10:27am UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/13 "2025-01-18T10:27:02Z")

</div>

Cargo also handles downloading and building dependencies.

---

<div class="post-metadata">

**Author:** ![Kyllingene](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/kyllingene/32/33899_2.png) [@Kyllingene](https://users.rust-lang.org/u/Kyllingene)\
**Post date:** [January 18, 2025, 4:07pm UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/14 "2025-01-18T16:07:19Z")

</div>

That's like saying rustc is "just" a tool for generating arguments for the assembler: while technically kinda true, it misses a whole lot of complexity.

---

<div class="post-metadata">

**Author:** ![MOCKBA](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/mockba/32/41423_2.png) [@MOCKBA](https://users.rust-lang.org/u/MOCKBA)\
**Post date:** [January 25, 2025, 1:32am UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/15 "2025-01-25T01:32:26Z")

</div>

You are absolutely correct. However if you need to prepare a distribution package where your Rust exe is only a tiny piece, you may need other tools. Installation, configuration, upgrading, and so on is an another story. Even you need Python to build rustc itself. So, Cargo is an amazing tool, but for a very specialized task. I use a different tool with wide range of functionality and building Rust components is a small piece of the range.

---

<div class="post-metadata">

**Author:** ![MOCKBA](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/mockba/32/41423_2.png) [@MOCKBA](https://users.rust-lang.org/u/MOCKBA)\
**Post date:** [January 25, 2025, 3:36am UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/17 "2025-01-25T03:36:06Z")

</div>

A good advice , thank you.

---

<div class="post-metadata">

**Author:** ![simonbuchan](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/simonbuchan/32/19939_2.png) [@simonbuchan](https://users.rust-lang.org/u/simonbuchan)\
**Post date:** [January 25, 2025, 5:47am UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/18 "2025-01-25T05:47:55Z")

</div>

Keep in mind that in the Windows 3 days Borland only had to port and maintain like a 1000 APIs, it's more like 100,000 now! It's better that the Windows API support is provided by Microsoft directly for pretty much everyone involved.

---

<div class="post-metadata">

**Author:** ![MOCKBA](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/mockba/32/41423_2.png) [@MOCKBA](https://users.rust-lang.org/u/MOCKBA)\
**Post date:** [January 25, 2025, 9:13pm UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/19 "2025-01-25T21:13:24Z")

</div>

I would happy to work with the Windows 3 subset supported by Borland. The major problem is currently to call just one Windows API function. As only it will start working, I can get 100,000 set easily.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [April 25, 2025, 9:14pm UTC](https://users.rust-lang.org/t/error-error-calling-dlltool-dlltool-exe-program-not-found/124236/20 "2025-04-25T21:14:10Z")

</div>

Closed on April 25, 2025, 9:14pm UTC

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
