【问题标题】:How to use libraries and headers in C++ with MinGW?如何在 MinGW 中使用 C++ 中的库和头文件?
【发布时间】:2020-11-02 05:48:14
【问题描述】:

我想使用 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

【问题讨论】:

  • 您可以尝试:g++ -L./path/to/lib/file.lib -I./path/to/headers test.cpp -o test,将您的包含 <eglew.h> 更改为 "eglew.h" 可能会有所帮助。
  • 您似乎必须输入错误的二进制文件。 MinGW 通常与.a 一起工作,而不是.lib

标签: c++ opengl mingw glew


【解决方案1】:

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

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

/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

【讨论】:

  • 向编译器请求警告是个好习惯
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-08
相关资源
最近更新 更多