{"id":2185,"date":"2022-02-13T07:46:47","date_gmt":"2022-02-13T13:46:47","guid":{"rendered":"https:\/\/www.becomebetterprogrammer.com\/?p=2185"},"modified":"2022-04-25T09:33:00","modified_gmt":"2022-04-25T14:33:00","slug":"rust-cargo-build-fails-link-exe-failed-exit-code-1","status":"publish","type":"post","link":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/rust-cargo-build-fails-link-exe-failed-exit-code-1\/","title":{"rendered":"Rust: cargo build fails `link.exe` failed: exit code: 1"},"content":{"rendered":"\n<p>With Rust gaining more and more popularity due to newer technologies such as Web3, developers have started to learn Rust to not only keep up with new trends but also expand their skillset. However, it is always disappointing whenever you run into errors when starting to execute code in a new programming language such as Rust.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"the-problem-cargo-build-fails-link-exe-failed\">The Problem: cargo build fails <code>link.exe<\/code> failed<\/h2>\n\n\n\n<p>In my case, I <a href=\"https:\/\/www.rust-lang.org\/tools\/install\" target=\"_blank\" rel=\"noreferrer noopener\">installed Rust<\/a> in Windows and attempted to build my first simple &#8220;Hello World&#8221; piece of code in Rust using <code>cargo build<\/code>. However, I came across the following error: <code>Error link.exe failed exit code 1<\/code>.<\/p>\n\n\n\n<p><strong>Note<\/strong>: I installed Rust in both, Windows Subsystem for Linux (WSL) and Windows. This error only appeared after installing Windows.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.becomebetterprogrammer.com\/wp-content\/uploads\/2022\/02\/Error-link.exe-failed-exit-code-1.png\" alt=\"\" class=\"wp-image-2186\" width=\"464\" height=\"51\" title=\"Error link.exe failed exit code 1\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2022\/02\/Error-link.exe-failed-exit-code-1.png 464w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2022\/02\/Error-link.exe-failed-exit-code-1-300x33.png 300w\" sizes=\"auto, (max-width: 464px) 100vw, 464px\" \/><figcaption>Error link.exe failed exit code 1<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"the-solution\">The Solution<\/h2>\n\n\n\n<p>After checking the <a href=\"https:\/\/rust-lang.github.io\/rustup\/index.html\" target=\"_blank\" rel=\"noreferrer noopener\">rustup book<\/a>, it talks about Rust having two ABIs on MSVC and the GNU. By default, Rust uses the MSVC ABI, which it was causing the <code>Error link.exe failed exit code 1<\/code>. <\/p>\n\n\n\n<p><strong>After installing and configuring the Rust GNU ABI, I didn&#8217;t have issues after running the <code>cargo build<\/code> command. <\/strong><\/p>\n\n\n\n<p>To install the GNU ABI, use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>rustup toolchain install stable-gnu<\/code><\/pre>\n\n\n\n<p>Depending on the Windows system you have, whether it is 32-bit or 64-bit, it will install a specific target. Since I have Windows 64-bit, it installed the target x86_64-pc-windows-gnu. Check out<a href=\"https:\/\/doc.rust-lang.org\/nightly\/rustc\/platform-support.html#tier-1-with-host-tools\" target=\"_blank\" rel=\"noreferrer noopener\"> the full list of tier 1 targets supported in Rust<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"628\" src=\"https:\/\/www.becomebetterprogrammer.com\/wp-content\/uploads\/2022\/02\/GNU-ABI-installed-1024x628.png\" alt=\"\" class=\"wp-image-2187\" title=\"GNU ABI installed\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2022\/02\/GNU-ABI-installed-1024x628.png 1024w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2022\/02\/GNU-ABI-installed-300x184.png 300w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2022\/02\/GNU-ABI-installed-768x471.png 768w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2022\/02\/GNU-ABI-installed.png 1081w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Rust GNU ABI installed<\/figcaption><\/figure><\/div>\n\n\n\n<p>The rustup book recommends the following command to change the Rust configuration in Windows.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>rustup set default-host x86_64-pc-windows-gnu<\/code><\/pre>\n\n\n\n<p>However, that did not work for me. If that doesn&#8217;t work for you either, use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>rustup default stable-x86_64-pc-windows-gnu<\/code><\/pre>\n\n\n\n<p>Now, try one more time running the <code>cargo build<\/code> command. You should not see errors when building the Rust executable file. <\/p>\n\n\n\n<p><strong>Note<\/strong>: For more information about how Rust works on Windows, it is suggested to read <a href=\"https:\/\/rust-lang.github.io\/rustup\/installation\/windows.html\" target=\"_blank\" rel=\"noreferrer noopener\">this<\/a>, which you can find in the rustup book.<\/p>\n\n\n\n<p><strong>Was this article helpful?<\/strong><\/p>\n\n\n\n<p>Share your thoughts by replying on Twitter of <a href=\"https:\/\/twitter.com\/bbprogrammer\" target=\"_blank\" rel=\"noreferrer noopener\">Become A Better Programmer<\/a> or to <a href=\"https:\/\/twitter.com\/arealesramirez\" target=\"_blank\" rel=\"noreferrer noopener\">personal my Twitter account<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-rich is-provider-twitter wp-block-embed-twitter\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"twitter-tweet\" data-width=\"550\" data-dnt=\"true\"><p lang=\"en\" dir=\"ltr\">We got a not-so-typical article for the kind of posts we share in Become a Better Programmer.<br><br>This time, we are sharing a solution for those Windows users having issues running cargo build command for the first time to run <a href=\"https:\/\/twitter.com\/hashtag\/rustlang?src=hash&amp;ref_src=twsrc%5Etfw\" target=\"_blank\" rel=\"noopener\">#rustlang<\/a> <a href=\"https:\/\/t.co\/dAQMn6UE2e\">https:\/\/t.co\/dAQMn6UE2e<\/a><\/p>&mdash; Become A Better Programmer (@bbprogrammer) <a href=\"https:\/\/twitter.com\/bbprogrammer\/status\/1492859043110694913?ref_src=twsrc%5Etfw\" target=\"_blank\" rel=\"noopener\">February 13, 2022<\/a><\/blockquote><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>With Rust gaining more and more popularity due to newer technologies such as Web3, developers have started to learn Rust to not only keep up with new trends but also expand their skillset. However, it is always disappointing whenever you run into errors when starting to execute code in a new programming language such as &#8230; <a title=\"Rust: cargo build fails `link.exe` failed: exit code: 1\" class=\"read-more\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/rust-cargo-build-fails-link-exe-failed-exit-code-1\/\" aria-label=\"More on Rust: cargo build fails `link.exe` failed: exit code: 1\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":2189,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[31],"tags":[],"class_list":["post-2185","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-rust","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts\/2185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/comments?post=2185"}],"version-history":[{"count":5,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts\/2185\/revisions"}],"predecessor-version":[{"id":2455,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts\/2185\/revisions\/2455"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/media\/2189"}],"wp:attachment":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/media?parent=2185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/categories?post=2185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/tags?post=2185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}