C++ C++;未针对对象文件链接的库(G+;+;)

C++ C++;未针对对象文件链接的库(G+;+;),c++,compilation,linker,g++,gnu,C++,Compilation,Linker,G++,Gnu,每当我尝试针对对象文件链接GLEW时,都会出现以下错误: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: Buffer.o:Buffer.cpp:(.text+0x1d): undefined reference to `_imp____glewGenBuffers' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe:

每当我尝试针对对象文件链接GLEW时,都会出现以下错误:

c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: Buffer.o:Buffer.cpp:(.text+0x1d): undefined reference to `_imp____glewGenBuffers'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: Buffer.o:Buffer.cpp:(.text+0x52): undefined reference to `_imp____glewDeleteBuffers'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: Buffer.o:Buffer.cpp:(.text+0x7c): undefined reference to `_imp____glewBindBuffer'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: Buffer.o:Buffer.cpp:(.text+0xa8): undefined reference to `_imp____glewBindBuffer'
collect2.exe: error: ld returned 1 exit status
Makefile:7: recipe for target 'main' failed
这将正确编译:

main: main.cpp Buffer.hpp Buffer.cpp
  g++ -o main.exe main.cpp Buffer.cpp -DGLEW_STATIC ${INCLUDE_PATH} ${LIB_PATH} ${LIBS}
这将返回上面显示的错误

main: main.cpp Buffer.o
  g++ -o main.exe main.cpp Buffer.o -DGLEW_STATIC ${INCLUDE_PATH} ${LIB_PATH} ${LIBS}

Buffer.o: Buffer.hpp Buffer.cpp
  g++ -c Buffer.cpp ${INCLUDE_PATH}

代码完全相同,所以我不知道问题出在哪里。我使用的是mingw32 make和g++(mingw)。

预处理器使用GLEW_STATIC来确定如何从GLEW API中预定义函数,因此在编译缓冲区对象时需要提供它。或者,您可以在包含GLEW.h之前在包含GLEW.h的文件中添加“#define GLEW_STATIC”,您根本不需要将其作为参数传递给g++。

请提供一个@AlanBirtles,这是我所能做到的最小值,我认为这是最小值,但不可复制。@drescherjm只需将任何库与使用该库的对象文件