C++库没有链接到对象文件(G++)



每当我尝试将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++。

相关内容

  • 没有找到相关文章

最新更新