'Linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1

I'm trying to follow a tutorial with Rust, and everything seems to be fine when the project is building, however when it's to compile the final project I get this error:

error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
  |
  = note: "x86_64-w64-mingw32-gcc" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-m64" "-Wl,--high-entropy-va" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsbegin.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.0.rcgu.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.1.rcgu.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.10.rcgu.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.11.rcgu.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.12.rcgu.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.13.rcgu.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.14.rcgu.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.15.rcgu.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.2.rcgu.o" 
"C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.3.rcgu.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.4.rcgu.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.5.rcgu.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.6.rcgu.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.7.rcgu.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.8.rcgu.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.opengl.78e8c60b-cgu.9.rcgu.o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.572cz1v33n8irwuf.rcgu.o" "-L" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps" "-L" "C:\\Users\\HTS\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\winapi-x86_64-pc-windows-gnu-0.4.0\\lib" "-L" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-Wl,-Bstatic" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\libsdl2-ff8e3aecaba1039f.rlib" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\librand-4852703721ce3987.rlib" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\librand-27387e802a09b3d3.rlib" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\libwinapi-02ff2b90b49e95d2.rlib" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\libsdl2_sys-14ec34eb6bd75e06.rlib" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\libbitflags-9af2d16a755593c6.rlib" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\liblazy_static-187a5db85e9be9d4.rlib" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\liblibc-44ccd068dcbcaeb4.rlib" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\libnum-da005076854413f9.rlib" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\libnum_iter-f65f0b20b4e2d668.rlib" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\libnum_integer-55ad1a282e0a6e5d.rlib" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\libnum_traits-d9adf69a437723aa.rlib" "-Wl,--start-group" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libstd-56555e8df3df487f.rlib" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libpanic_unwind-04dfc4a5db6cb4f5.rlib" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libobject-e582f52592ec7f47.rlib" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libmemchr-a1a4dcc32e76e372.rlib" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libaddr2line-627bcebbbc102a48.rlib" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libgimli-be04d4d5349d30fd.rlib" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libstd_detect-db47bdfceba1a4fb.rlib" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\librustc_demangle-dee726504430f253.rlib" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libhashbrown-437c3d2676cc0788.rlib" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\librustc_std_workspace_alloc-1270bba6b8f30349.rlib" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libunwind-f8f2892b852b8ad4.rlib" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcfg_if-c1b181d856fd1e1d.rlib" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\liblibc-f05d25f40b11c06d.rlib" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\liballoc-0feff3ebeb068fdc.rlib" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\librustc_std_workspace_core-ff80f052342e9644.rlib" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcore-c879fd37675b8e5a.rlib" "-Wl,--end-group" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcompiler_builtins-36a35a68f30e9765.rlib" "-Wl,-Bdynamic" "-lwinapi_advapi32" "-lwinapi_credui" "-lwinapi_kernel32" "-lwinapi_secur32" "-lSDL2" "-lkernel32" "-lws2_32" "-lbcrypt" "-ladvapi32" "-luserenv" "-lkernel32" "-lgcc_eh" "-l:libpthread.a" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "-Wl,--nxcompat" "-L" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-o" "C:\\Users\\HTS\\Desktop\\OpenGL\\target\\debug\\deps\\opengl-c7838aa6ca0d585e.exe" "-Wl,--gc-sections" "-no-pie" "-nodefaultlibs" "C:\\Users\\HTS\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsend.o"
  = note: C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2
          collect2.exe: error: ld returned 1 exit status


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

Caused by:
  process didn't exit successfully: `set CARGO=\\?\C:\Users\HTS\.rustup\toolchains\stable-x86_64-pc-windows-gnu\bin\cargo.exe&& set CARGO_BIN_NAME=opengl&& set CARGO_CRATE_NAME=opengl&& set CARGO_MANIFEST_DIR=C:\Users\HTS\Desktop\OpenGL&& set CARGO_PKG_AUTHORS=""&& set CARGO_PKG_DESCRIPTION=""&& set CARGO_PKG_HOMEPAGE=""&& set CARGO_PKG_LICENSE=""&& set CARGO_PKG_LICENSE_FILE=""&& set CARGO_PKG_NAME=opengl&& set CARGO_PKG_REPOSITORY=""&& set CARGO_PKG_VERSION=0.1.0&& set CARGO_PKG_VERSION_MAJOR=0&& set CARGO_PKG_VERSION_MINOR=1&& set CARGO_PKG_VERSION_PATCH=0&& set CARGO_PKG_VERSION_PRE=""&& set CARGO_PRIMARY_PACKAGE=1&& set PATH="C:\Users\HTS\Desktop\OpenGL\target\debug\deps;C:\Users\HTS\.rustup\toolchains\stable-x86_64-pc-windows-gnu\bin;C:\Users\HTS\.cargo\bin;C:\Users\HTS\.rustup\toolchains\stable-x86_64-pc-windows-gnu\bin;C:\Program Files (x86)\VMware\VMware Player\bin\;C:\Program Files\Microsoft\jdk-11.0.12.7-hotspot\bin;C:\VulkanSDK\1.2.189.2\Bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\AdoptOpenJDK\jdk-14.0.2.12-hotspot\bin;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64_win\compiler;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\nodejs\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Go\bin;C:\MinGW64\bin;C:\CMake\bin;C:\Users\HTS\.cargo\bin;C:\Users\HTS\AppData\Local\Programs\Python\Python38\Scripts\;C:\Users\HTS\AppData\Local\Programs\Python\Python38\;C:\Users\HTS\AppData\Local\Programs\Python\Python37\Scripts\;C:\Users\HTS\AppData\Local\Programs\Python\Python37\;C:\Users\HTS\Desktop\ffmpeg-4.4.1-full_build\bin\ffmpeg.exe;C:\Users\HTS\AppData\Local\Microsoft\WindowsApps;C:\Users\HTS\go\bin;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.3\bin;C:\Users\HTS\AppData\Local\Microsoft\WindowsApps;C:\Users\HTS\.dotnet\tools;C:\Users\HTS\AppData\Roaming\npm;C:\Users\HTS\AppData\Local\GitHubDesktop\bin;C:\Users\HTS\AppData\Local\bin\NASM;C:\Program Files\Pypy - 3.8;C:\Users\HTS\.dotnet\tools;C:\Users\HTS\Desktop\ffmpeg-4.4.1-full_build\bin;C:\Program Files (x86)\Nmap;C:\MinGW\bin;C:\Users\HTS\AppData\Local\Programs\Microsoft VS Code\bin;C:\MinGW\mingw32\bin;C:\Program Files (x86)\GnuWin32\bin;C:\Users\HTS\go\bin;"&& rustc --crate-name opengl --edition=2021 src\main.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C 
debuginfo=2 -C metadata=c7838aa6ca0d585e -C extra-filename=-c7838aa6ca0d585e --out-dir C:\Users\HTS\Desktop\OpenGL\target\debug\deps -C incremental=C:\Users\HTS\Desktop\OpenGL\target\debug\incremental -L dependency=C:\Users\HTS\Desktop\OpenGL\target\debug\deps --extern sdl2=C:\Users\HTS\Desktop\OpenGL\target\debug\deps\libsdl2-ff8e3aecaba1039f.rlib -L native=C:\Users\HTS\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-x86_64-pc-windows-gnu-0.4.0\lib` (exit code: 1)

I tried searching everywhere, no luck. I reinstalled MinGW, cargo, still nothing. And I have no idea what -lSDL2 is and if I'm missing some lib...



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source