How to connect the library using MinGW?

Decided not to use Visual studio or Code::Blocks, installed MinGW. The compilation seems clear. Got another question, how to connect the library. Watched a couple of videos, read a couple of articles, but never found. As I understand this requires linking. Let's say I would like to use GLFW. Threw the desired files into the folders of MinGW and prescribed:
#include <GLFW/glfw3.h>
int main()
{
glfwInit();
 return 0;
}

without glfwInit compiles fine but gives this:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\kitsuro\AppData\Local\Temp\ccOL0feh.o:Minecraft.cpp:(.text+0xc): undefined reference to `glfwInit'

As a "Text editor" I use Sublime Text 3.
April 19th 20 at 12:07
2 answers
April 19th 20 at 12:09
Solution
gcc-L<path to directory with libraries> -l<library name>
the name of the library
it should be 1 file? I have in the directory a dll file to specify it? - Troy.Walter commented on April 19th 20 at 12:12
@Troy.Walter, one library - one file - one key. Libraries can be any number. Not need to specify the file name and the library name. And most likely you need a file with the extension .aand not .dll. In my case the command looks like this:

gcc-IC:\MinGW\x64\env\include -LC:\MinGW\x64\env\lib hello.c-lglfw3 -lopengl32 -lgdi32

The order of libraries is important. - Alyson_Bayer commented on April 19th 20 at 12:15
@Alyson_Bayer,
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\MinGW\mingw64\lib/libglfw3.a when searching for-lglfw3
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\MinGW\mingw64\lib/glfw3.dll when searching for-lglfw3
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\MinGW\mingw64\lib\libglfw3.a when searching for-lglfw3
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../lib/libglfw3.a when searching for-lglfw3
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../lib/glfw3.dll when searching for-lglfw3
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../lib\libglfw3.a when searching for-lglfw3
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../libglfw3.a when searching for-lglfw3
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../glfw3.dll when searching for-lglfw3
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../..\libglfw3.a when searching for-lglfw3
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\MinGW\mingw64\lib/libglfw3.a when searching for-lglfw3
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\MinGW\mingw64\lib/glfw3.dll when searching for-lglfw3
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../lib/libglfw3.a when searching for-lglfw3
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../lib/glfw3.dll when searching for-lglfw3
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../libglfw3.a when searching for-lglfw3
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../glfw3.dll when searching for-lglfw3
C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find-lglfw3
collect2.exe: error: ld returned 1 exit status

that's what happens. When downloaded glfw in the archive folder include and lib. In lib were 3 files: glfw3.dll, libglfw3.a, libglfw3dll.a. I was transferred to the correct folder, did include. prescribed and 1 and option 2 (Cheated all the way if that). The result is the same. - Troy.Walter commented on April 19th 20 at 12:18
@Troy.Walter, most likely you downloaded the wrong version. - Alyson_Bayer commented on April 19th 20 at 12:21
@Alyson_BayerIs a Windows pre-compiled binaries version from the official website. What was supposed to be at the right version? And where to take it?) - Troy.Walter commented on April 19th 20 at 12:24
@Troy.Walter, at least a bit. The message "skipping incompatible" means that the library has an incompatible ABI. - Alyson_Bayer commented on April 19th 20 at 12:27
@Alyson_Bayer, Replaced the files, but...
C:\MinGW\mingw64\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x8f): undefined reference to `__imp_CreateDCW'
C:\MinGW\mingw64\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xc6): undefined reference to `__imp_GetDeviceCaps'
C:\MinGW\mingw64\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x123): undefined reference to `__imp_DeleteDC'
C:\MinGW\mingw64\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x263): undefined reference to `__imp_GetDeviceCaps'
C:\MinGW\mingw64\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x86e): undefined reference to `__imp_GetDeviceCaps'
C:\MinGW\mingw64\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x9be): undefined reference to `__imp_GetDeviceCaps'
C:\MinGW\mingw64\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xda9): undefined reference to `__imp_CreateDCW'
C:\MinGW\mingw64\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xdb8): undefined reference to `__imp_GetDeviceGammaRamp'
C:\MinGW\mingw64\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xdc4): undefined reference to `__imp_DeleteDC'
C:\MinGW\mingw64\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xf2a): undefined reference to `__imp_CreateDCW'
C:\MinGW\mingw64\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xf39): undefined reference to `__imp_SetDeviceGammaRamp'
C:\MinGW\mingw64\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xf42): undefined reference to `__imp_DeleteDC'
C:\MinGW\mingw64\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xbb): undefined reference to `__imp_CreateDIBSection'
C:\MinGW\mingw64\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xf4): undefined reference to `__imp_CreateBitmap'
C:\MinGW\mingw64\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x1af): undefined reference to `__imp_DeleteObject'
C:\MinGW\mingw64\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x230): undefined reference to `__imp_DeleteObject'
C:\MinGW\mingw64\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x2cf): undefined reference to `__imp_CreateRectRgn'
C:\MinGW\mingw64\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x30a): undefined reference to `__imp_DeleteObject'
C:\MinGW\mingw64\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x363): undefined reference to `__imp_DeleteObject'
C:\MinGW\mingw64\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x4589): undefined reference to `__imp_CreateDIBSection'
C:\MinGW\mingw64\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x45c2): undefined reference to `__imp_CreateBitmap'
C:\MinGW\mingw64\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x4678): undefined reference to `__imp_DeleteObject'
C:\MinGW\mingw64\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x46f3): undefined reference to `__imp_DeleteObject'
C:\MinGW\mingw64\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x14a): undefined reference to `__imp_SwapBuffers'
C:\MinGW\mingw64\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x3f6): undefined reference to `__imp_ChoosePixelFormat'
C:\MinGW\mingw64\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x404): undefined reference to `__imp_SetPixelFormat'
C:\MinGW\mingw64\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xcc4): undefined reference to `__imp_DescribePixelFormat'
C:\MinGW\mingw64\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xcde): undefined reference to `__imp_SetPixelFormat'
C:\MinGW\mingw64\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1310): undefined reference to `__imp_DescribePixelFormat'
C:\MinGW\mingw64\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1633): undefined reference to `__imp_DescribePixelFormat'
collect2.exe: error: ld returned 1 exit status
- Troy.Walter commented on April 19th 20 at 12:30
@Troy.Walter, you are lenquete libgdi32. - Alyson_Bayer commented on April 19th 20 at 12:33
@Alyson_Bayer, Oh. I thought at first that it as an example of other libraries. Stupid. Thank you very much) - Troy.Walter commented on April 19th 20 at 12:36
April 19th 20 at 12:11
It's a good start and the fact that @Alyson_Bayer advised, but in General you have to read about some build system like CMake, and about the process of connecting external dependencies. May be even worth it to ask Conan-Ohm or Vcpkgeat.

You will find many interesting.

And, Yes, again it is better to obtain a basic knowledge of the build process C/C++ programs. "As I understand it this requires linking" - that's the point you need to improve. Otherwise you will long suffer.
Thank you for reading. - Troy.Walter commented on April 19th 20 at 12:14

Find more questions by tags G++MinGWC++