C
C
covid242020-04-15 13:58:34
C++ / C#
covid24, 2020-04-15 13:58:34

How to include libraries using MinGW?

Decided not to use Visual studio or Code::Blocks, installed MinGW. With compilation it seems understood. Another question arose, how to connect libraries. I watched a couple of videos, read a couple of articles, but did not find it. As far as I understand, this requires a link. Let's say I want to connect GLFW. I threw the necessary files into the MinGW folders and wrote:

#include <GLFW/glfw3.h>
int main()
{
    glfwInit();
  return 0;
}

without glfwInit it compiles fine, but with this it produces:
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'

I use Sublime Text 3 as "Text editor".

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2020-04-15
@covid24

gcc -L<путь до каталога с библиотеками> -l<имя библиотеки>

S
Stanislav Makarov, 2020-04-15
@Nipheris

For starters, the fact that Sergey Gornostaev advised is enough , but in general you should read about some kind of assembly system, for example about CMake, and about the process of connecting external dependencies. It might even be worth asking Conan or Vcpkg .
A lot of interesting things are waiting for you.
Ah, yes, it's better to get a basic knowledge of the process of building C/C++ programs first. "As I understand it, linking is needed for this" - this point needs to be greatly improved. Otherwise, you will suffer for a long time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question