如何将C++中的库和头与MinGW一起使用

How to use libraries and headers in C++ with MinGW?

本文关键字:MinGW 一起 C++      更新时间:2023-10-16

我想使用OpenGL GLEW库。我已经下载了二进制文件,它的文件夹在我的.cpp文件所在的文件夹中。我的.cpp文件使用#include <eglew.h>

我应该如何格式化MinGW的命令以编译.cpp文件?我是像g++ -L./path/to/lib/file.lib test.cpp -o test那样使用.lib文件编译,还是像链接头文件g++ -I./path/to/headers test.cpp -o test那样做其他事情?

为了更好地理解事情,最好将编译和链接步骤分开。如果你出现错误,那么你也会知道问题发生在哪一步。

我假设你有以下文件夹/文件:

/path/to/eglew/include/GL/eglew.h
/path/to/eglew/lib/libglew32.a

编译:

g++ -Wall -c -o test.o test.cpp -I/path/to/eglew/include/GL

链接:

g++ -o test.exe test.o -L/path/to/eglew/lib -lglew32

尽管我希望看到#include <GL/eglew.h>,在这种情况下,链接器包含标志应该是-I/path/to/eglew/include