Background
Let us review the steps one will take to build a Rust application that will be ran on a 32-bit MS Windows application.
Lineage
- Rust:- Cargo Build Error – “error: linker `link.exe` not found”
Date Published:- 2023-March-28th
Link
Outline
Here are the steps that we will follow:-
- Targeted Platforms
- Review Targeted Platforms ( Pre )
- Add Specific Target Platforms
- Review Target Platforms ( Post )
- Project
- Build Project
- Artifacts
- List Artifacts
- Inspect Artifacts
- Test App
- Watch
- Task Manager
- Watch
Targeted Platforms
Review Targeted Platforms ( Pre )
Let us list available targeted platforms.
Command:- Rustup target list
Syntax
rustup target list
Sample
Sample – List Target – Windows
rustup target list | findstr /i "windows"
Output
Output – List Target – Windows
>rustup target list | findstr /i "windows" aarch64-pc-windows-msvc i586-pc-windows-msvc i686-pc-windows-gnu i686-pc-windows-msvc x86_64-pc-windows-gnu x86_64-pc-windows-msvc (installed) >
Images – List – Target – Windows
Explanation
Explanation – List – Target – Windows
- A lone MS Windows Platform is targeted
- x86_64-pc-windows-msvc (installed)
Add Targeted Platforms
Let us go over how to target new platforms.
Command:- Rustup target add
Syntax
rustup target add [platform]
Sample
Sample – Add Target – Windows
rustup target add i686-pc-windows-msvc
Output
Output – Add Target – Windows
>rustup target add i686-pc-windows-msvc info: downloading component 'rust-std' for 'i686-pc-windows-msvc' info: installing component 'rust-std' for 'i686-pc-windows-msvc' 26.9 MiB / 26.9 MiB (100 %) 8.9 MiB/s in 2s ETA: 0s
Image – Add Target – Windows
Explanation
Explanation – List – Target – Windows
- Component
- i686-pc-windows-msvc
- Tasks
- Downloading component
- Installing component
- Size
- 26.9 MB
- 8 MiB/s
- 2s ETA
- Tasks
- i686-pc-windows-msvc
Review Targeted Platforms ( Post )
For those who targeted platforms were not currently available, and they needed to add it, please review targeted platforms post installing a new target.
Command:- Rustup target list
Syntax
rustup target list
Sample
Sample – List Target – Windows
rustup target list | findstr /i "windows"
Output
Output – List Target – Windows
>rustup target list | findstr /i "windows" aarch64-pc-windows-msvc i586-pc-windows-msvc i686-pc-windows-gnu i686-pc-windows-msvc (installed) x86_64-pc-windows-gnu x86_64-pc-windows-msvc (installed) >
Images – List – Target – Windows
Explanation
Explanation – List – Target – Windows
We reviewed available targets and filtered on Windows, here are our “installed” matches
- i686-pc-windows-msvc (installed)
- x86_64-pc-windows-msvc (installed)
Build Project
Build MS Windows 32-bit Project
Command:- Cargo Build
Syntax
cargo build
Sample
Sample – Build – Target – Windows – 32 Bit
cargo build --release --target x86_64-pc-windows-msvc
Output
Output – Build – Target – Windows – 32 Bit – Text
>cargo build --release --target x86_64-pc-windows-msvc Compiling hello_world v0.1.0 (C:\personal\dadeniji\script\rust\hello_world) Finished release [optimized] target(s) in 1.18s
Output – Build – Target – Windows – 32 Bit – Image
Build MS Windows 64-bit Project
Command:- Cargo Build
Syntax
cargo build
Sample
Sample – Build – Target – Windows – 64 Bit
cargo build --release --target x86_64-pc-windows-msvc
Output
Output – Build – Target – Windows – 64 Bit – Text
>cargo build --release --target x86_64-pc-windows-msvc Compiling hello_world v0.1.0 (C:\personal\dadeniji\script\rust\hello_world) Finished release [optimized] target(s) in 0.49s
Output – Build – Target – Windows – 64 Bit – Image
Artifacts
List Artifacts
Dir Command
Syntax
dir *.exe /s
Sample
List Windows Binaries ( *.exe )
dir target\*.exe /s /b
Output
List Windows Binaries ( *.exe )
>dir target\*.exe /s /b | findstr /V "\deps\" C:\personal\dadeniji\script\rust\hello_world\target\i686-pc-windows-msvc\release\hello_world.exe C:\personal\dadeniji\script\rust\hello_world\target\x86_64-pc-windows-msvc\release\hello_world.exe >
Explanation
- target\i686-pc-windows-msvc\release\hello_world.exe
- target\x86_64-pc-windows-msvc\release\hello_world.exe
Inspect Artifacts
Determine Artifact Bitness
Dumpbin.exe
Syntax
dumpbin [file]
Sample – Windows – 32 Bit
Inspect Windows Binaries – 32 Bit
dumpbin /headers target\i686-pc-windows-msvc\release\hello_world.exe | findstr /I "machine"
Output
Text
>dumpbin /headers target\i686-pc-windows-msvc\release\hello_world.exe | findstr /I "machine" 14C machine (x86) 32 bit word machine >
Image
Explanation
- Looked at the executable’s header
- Filtered on machine
- Matched:-
- (x86)
- 32 bit
Sample – Windows – 64 Bit
Inspect Windows Binaries – 64 Bit
dumpbin /headers target\x86_64-pc-windows-msvc\release\hello_world.exe | findstr /I "machine"
Output
Text
>dumpbin /headers target\x86_64-pc-windows-msvc\release\hello_world.exe | findstr /I "machine" 8664 machine (x64)
Image
Explanation
- Looked at the executable’s header
- Filtered on machine
- Matched:-
- 8664 machine (x64)
Test App
Watch
Task Manager
We will run application and watch via Task Manager
Run Application
Syntax
[application-name]
Sample
Sample – Windows – x32
target\i686-pc-windows-msvc\release\hello_world.exe
Output
Image – Windows -x32 – Console
Image – Windows -x32 – Task Manager
Explanation
- Task Manager
- Columns
- Platform:- 32 bit
- Columns
Tools
- Find – Option /v
- find /? ( Command Help )
- /V Displays all lines NOT containing the specified string.
- Skipped files in the deps folder
- find /V “\deps\”
- find /? ( Command Help )
- Findstr – Option /V
- findstr /? ( Command Help )
- /V Prints only lines that do not contain a match.
- Skipped files in the deps folder
- findstr /V “\deps\”
- findstr /? ( Command Help )
Summary
__, I am really a son of Rakim.
Everything takes too long around here!