简体   繁体   中英

C++ libraries not linking against object files (G++)

Whenever I try linking GLEW against an object file, I get this error:

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

This compiles properly:

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

This returns the error shown above.

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}

The code is the exact same code, so I don't know what the problem is. I'm using mingw32-make and g++ (mingw).

GLEW_STATIC is used by the pre-processor to determine how to pre-define the functions from the glew API so you need to supply it when compiling the buffer object. Alternatively you could add '#define GLEW_STATIC' in the file that includes glew.h before glew.h is included and you wouldn't need to pass it as an argument to g++ at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM