Rust:- Cargo Build Error – “error: linker `link.exe` not found”

Background

I was preparing to download a rust application’s source code and see if I can compile it locally.

 

Hello World

I have a single one liner and thought it best to see if that project still compiles.

See, I have not worked on Rust in many, many months.

 

Build

Syntax


cargo build

Sample


cargo build 

Output

Output – Image

Output – Text


>cargo build
Compiling hello_world v0.1.0 (C:\hello_world)
error: linker `link.exe` not found
|
= note: program not found

note: the msvc targets depend on the msvc linker but `link.exe` was not found

note: please ensure that Visual Studio 2017 or later, or Build Tools for Visual Studio were installed with the Visual C++ option.

note: VS Code is a different product, and is not sufficient.

error: could not compile `hello_world` due to previous error

>

Explanation

The error message has some important key notes:-

  1. Linker ( Link.exe )
    • Linker link.exe not found
  2. MSVC Target
    • The msvc targets depend on the msvc linker but `link.exe` was not found
  3. Visual Studio
    • Required Installs
      • Visual Studio 2017 or later
      • Build Tools for Visual Studio with the Visual C++ Option
  4. VS Code
    • Immaterial
      • VS Code is a different product and is not sufficient

 

Troubleshooting

Outline

  1. Application Compile Tools
    • Link
    • MSBuild
  2. Link – Find Binary
    • dir
    • where
  3. Environment Variable
    • Path
    • Include
    • Lib

Application Compile Tools

Link

Syntax

link.exe

Sample

link.exe

Output
Output – Image

Output – Text

'link' is not recognized as an internal or external command, operable program or batch file. 

MSBuild

Syntax

msbuild.exe

Sample

msbuild.exe

Output
Output – Image
Output – Text

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>msbuild
Microsoft (R) Build Engine version 16.11.1+3e40a09f8 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>

Link – Find Binary

dir

Syntax

dir link.exe

Sample

cd /D c:\

dir link.exe

Output
Output – Image

Output – Text

>dir link.exe /s
 Volume in drive C is Windows
 Volume Serial Number is 8ADD-49CB

 Directory of C:\Program Files\Git\usr\bin

10/13/2021  11:23 PM            32,798 link.exe
               1 File(s)         32,798 bytes

 Directory of C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\SDK\ScopeCppSDK\vc15\VC\bin

09/21/2022  02:26 PM         1,400,424 link.exe
               1 File(s)      1,400,424 bytes

 Directory of C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin

03/19/2010  02:02 PM           852,296 link.exe
               1 File(s)        852,296 bytes

 Directory of C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64

03/19/2010  02:02 PM         1,039,688 link.exe
               1 File(s)      1,039,688 bytes

 Directory of C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64

03/19/2010  02:02 PM           852,296 link.exe
               1 File(s)        852,296 bytes

     Total Files Listed:
               5 File(s)      4,177,502 bytes
               0 Dir(s)  632,224,698,368 bytes free


Explanation

The Link executable is found in the following folders:-

  1. Git
    • C:\Program Files\Git\usr\bin
  2. Microsoft
    • Visual Studio
      • Visual Studio 2019
        • Community
          • C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\SDK\ScopeCppSDK\vc15\VC\bin
      • Visual Studio 10.0
        • VC
          • C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin
          • C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64
          • C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64

 

where

Syntax

cd c:\

where link.exe

Sample

cd c:\

where link.exe

Output
Output – Image

Output – Text

where link.ee

INFO: could not find files for the given pattern(s).

Explanation

The Link executable is not found in our path.

 

 

OS Environment Variable

Outline

Please review and make a note of the following environment variables:-

  1. INCLUDE
  2. LIB
  3. LIBPATH
  4. PATH

Include

Syntax

echo [environment-variable]

Sample

echo %INCLUDE%

Output
Output – Image

Output – Text

>echo %INCLUDE%
C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um</pre>

 

Lib

Syntax

echo [environment-variable]

Sample

echo %LIB%

Output
Output – Image

Output – Text

>echo %LIB%
C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x86

Libpath

Syntax

echo [environment-variable]

Sample

echo %LIBPATH%

Output

 

Output – Image

Output – Text

>echo %LIBPATH%
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319

path

Syntax

echo [environment-variable]

Sample

echo %PATH%

Output

Will skip sharing our path. As doing so may distract from this specific post.

 

Remediation

Outline

  1. Visual Studio
    • Installation
      • Workload

 

Visual Studio

Installation

Workload

Outline
    1. Review Installed Features
    2. Add Features – Workload – Desktop Development with C++

 

Review Install Features
  1. Access Workloads Tab
    • Is “Desktop development with C++” workload installed
    • In our case “Desktop development with C++” was not installed

 

 

Add Features
  1. Add Workload – Desktop Development with C++
    • Add Workload “Desktop development with C++
      • Included
        • C++ core desktop features
      • Optional
        • MSVC v142 – VS 2019 C++ x64/x86 build tool
        • Windows 10 SDK
        • C++ CMake tools for windows

 

Images

 

 Image – Pre Changes – Desktop Development with C++

Image – Pre Changes – Desktop Development with C++ – Option Checked

Image – Pre Changes – Desktop Development with C++ – Option Processing – 01

Image – Installing – Desktop Development with C++ – Option Processing – Downloading & Verification – 01

Image – Installing – Desktop Development with C++ – Option Processing – Downloading & Verification – 02

Image – Installing – Desktop Development with C++ – Option Processing – Downloading & Verification – 03

Image – Installing – Desktop Development with C++ – Option Processing – Completed

Verification

Outline

  1. Find Binary
    • where
    • dir
  2. OS Environment Variable
    • INCLUDE
    • LIB
    • LIBPATH
    • PATH
  3. Link.exe
    • Metadata
      • Version Number

 

Link – Find Binary

Where

Syntax
 

where [binary]

Sample
 

where link.exe 

Output

 

Output – Image

Output – Text

where link.exe

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\link.exe

Explanation

    1. Microsoft Visual Studio
      • Bitness:- x86
      • Product:- Visual Studio 10.0
      • Language:- VC
      • Processor Type:- AMD64

 

dir

 

Syntax
 

dir [binary]

Sample
 

dir link.exe /s 

Output

 

Output – Image

 

 

Output – Text

>dir link.exe /s
 Volume in drive C is Windows
 Volume Serial Number is 8ADD-49CB

 Directory of C:\Program Files\Git\usr\bin

10/13/2021  11:23 PM            32,798 link.exe
               1 File(s)         32,798 bytes

 Directory of C:\Program Files\Microsoft SQL Server\MSSQL15.V2019\MSSQL\Binn\Xtp\VC\bin

04/11/2022  05:59 PM         1,707,936 link.exe
               1 File(s)      1,707,936 bytes

 Directory of C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Binn\Xtp\VC\bin

10/08/2022  07:40 AM         2,246,088 link.exe
               1 File(s)      2,246,088 bytes

 Directory of C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\SDK\ScopeCppSDK\vc15\VC\bin

09/21/2022  02:26 PM         1,400,424 link.exe
               1 File(s)      1,400,424 bytes

 Directory of C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64

03/27/2023  02:41 PM         2,244,512 link.exe
               1 File(s)      2,244,512 bytes

 Directory of C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x86

03/27/2023  02:41 PM         2,244,528 link.exe
               1 File(s)      2,244,528 bytes

 Directory of C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x64

03/27/2023  02:40 PM         1,896,376 link.exe
               1 File(s)      1,896,376 bytes

 Directory of C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x86

03/27/2023  02:40 PM         1,896,376 link.exe
               1 File(s)      1,896,376 bytes

 Directory of C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin

03/19/2010  02:02 PM           852,296 link.exe
               1 File(s)        852,296 bytes

 Directory of C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64

03/19/2010  02:02 PM         1,039,688 link.exe
               1 File(s)      1,039,688 bytes

 Directory of C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64

03/19/2010  02:02 PM           852,296 link.exe
               1 File(s)        852,296 bytes

     Total Files Listed:
              11 File(s)     16,413,318 bytes
               0 Dir(s)  619,674,832,896 bytes free

>


 

OS Environment Variable

Outline

Please review and make a note of the following environment variables:-

    1. INCLUDE
    2. LIB
    3. LIBPATH
    4. PATH

 

Include

Syntax

echo [environment-variable]

Sample

echo %INCLUDE%

Output
Output – Image

Output – Text

>echo %INCLUDE%
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\ATLMFC\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt

Explanation
  1. Microsoft
    • Visual Studio
      • Microsoft Visual Studio 10.0
        • VC
          • C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE
          • C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\INCLUDE
    • SDK
      • v7.0A
        • C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include;

 

Lib

Syntax

echo [environment-variable]

Sample

echo %LIB%

Output

 

Output – Image

Output – Text
>echo %LIB%
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\LIB\amd64;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\LIB\amd64;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\x64;

>
Explanation
  1. Visual Studio
    • Visual Studio v10.0
      • C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\LIB\amd64
      • C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\LIB\amd64
  2. SDK
    • C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\x64;

 

Libpath

Syntax

echo [environment-variable]

Sample

echo %LIBPATH%

Output
Output – Image

Output – Text
>echo %LIBPATH%
C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319;C:\WINDOWS\Microsoft.NET\Framework64\v3.5;C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319;C:\WINDOWS\Microsoft.NET\Framework\v3.5;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\LIB\amd64;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\LIB\amd64;

>
Explanation
  1. Microsoft
    • .Net Framework
      • C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319
      • C:\WINDOWS\Microsoft.NET\Framework64\v3.5
      • C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319
      • C:\WINDOWS\Microsoft.NET\Framework\v3.5
    • Visual Studio
      • Visual Studio V 10.0
        • C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\LIB\amd64
        • C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\LIB\amd64

path

Syntax

echo [environment-variable]

Sample

echo %PATH%

Output

Will skip sharing our path.

As doing so may distract from this specific post.

Link – Metadata

Version

Syntax
 

link.exe

Sample
 

link | find "Version"

Output

Output – Image

Output – Text

>link | find "Version"
Microsoft (R) Incremental Linker Version 10.00.30319.01

Explanation

  1. Microsoft Visual Studio
    • Version Number
      • 10.00.30319.01

Summary

In summary, to get our simple Hello World rust’s application to compile, we seemingly had  Microsoft’s Visual Studio “Desktop Development with C++” workload installed.

During the install or during your review, please make sure that the core and sub-component listed below are installed:-

  1. Add Workload “Desktop development with C++
    • Included
      • C++ core desktop features
    • Optional
      • MSVC v142 – VS 2019 C++ x64/x86 build tool
      • Windows 10 SDK
      • C++ CMake tools for windows

 

Unfortunately, life has plenty of blindness.

One thought on “Rust:- Cargo Build Error – “error: linker `link.exe` not found”

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s