C++ 库不链接目标文件 (G++)
C++ libraries not linking against object files (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}
这returns上面显示的错误。
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 的文件中添加“#define GLEW_STATIC”,然后再包含 glew.h,您根本不需要将其作为参数传递给 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}
这returns上面显示的错误。
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 的文件中添加“#define GLEW_STATIC”,然后再包含 glew.h,您根本不需要将其作为参数传递给 g++。