OpenGL-将glew和glut libs和dll与g ++链接

问题描述 投票:0回答:1

我实际上花了5个小时试图获取OpenGl代码以使用g ++进行编译。

我尝试了很多事情,甚至都不记得在这里发布。

我想我的问题是将.libs和.dll与g ++链接。

我已将所有库文件和dll存放在名为lib的文件夹中。我做的最后一件事是发出此命令:

g++ -I./include mytest1.cpp -L./lib 

仍然没有用。有什么帮助吗?

编辑:我在窗户上。我不认为我正在使用FreeGlut,文件名为glut32.dll和glut32.lib

这是编译器错误:

C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x7): undefined
reference to `_imp____glewDeleteVertexArrays'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x22): undefined
 reference to `_imp____glewDeleteBuffers'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x51): undefined
 reference to `_imp____glewBindVertexArray'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x6a): undefined
 reference to `_imp____glewBindBuffer'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x8b): undefined
 reference to `_imp____glewBufferData'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0xb4): undefined
 reference to `_imp____glewEnableVertexAttribArray'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0xc7): undefined
 reference to `_imp____glewVertexAttribPointer'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x103): undefine
d reference to `_imp____glewBindBuffer'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x127): undefine
d reference to `_imp____glewBufferData'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x150): undefine
d reference to `_imp____glewEnableVertexAttribArray'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x163): undefine
d reference to `_imp____glewVertexAttribPointer'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x19f): undefine
d reference to `_imp____glewBindBuffer'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x1c3): undefine
d reference to `_imp____glewBufferData'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x206): undefine
d reference to `_imp____glewBindVertexArray'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x221): undefine
d reference to `_imp____glewBindVertexArray'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x265): undefine
d reference to `glDrawElements@16'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x26d): undefine
d reference to `_imp____glewBindVertexArray'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x28f): undefine
d reference to `glClear@4'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x2af): undefine
d reference to `glFlush@0'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x3e6): undefine
d reference to `_imp____glewUniformMatrix4fv'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x434): undefine
d reference to `glutPostRedisplay'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x581): undefine
d reference to `_imp____glewUniformMatrix4fv'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x5cf): undefine
d reference to `glutPostRedisplay'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x633): undefine
d reference to `glViewport@16'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x68e): undefine
d reference to `_imp____glewUniformMatrix4fv'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x718): undefine
d reference to `glClearColor@16'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x833): undefine
d reference to `_imp____glewGenVertexArrays'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x84e): undefine
d reference to `_imp____glewGenBuffers'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x906): undefine
d reference to `initshaders(unsigned int, char const*)'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x91f): undefine
d reference to `initshaders(unsigned int, char const*)'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x93b): undefine
d reference to `initprogram(unsigned int, unsigned int)'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x945): undefine
d reference to `_imp____glewGetUniformLocation'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x966): undefine
d reference to `_imp____glewGetUniformLocation'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x987): undefine
d reference to `_imp____glewUniformMatrix4fv'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0x9d5): undefine
d reference to `_imp____glewUniformMatrix4fv'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0xa61): undefine
d reference to `glutInit'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0xa6d): undefine
d reference to `glutInitDisplayMode'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0xa81): undefine
d reference to `glutInitWindowSize'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0xa95): undefine
d reference to `glutInitWindowPosition'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0xaa1): undefine
d reference to `glutCreateWindow'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0xaa6): undefine
d reference to `_imp__glewInit@0'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0xabc): undefine
d reference to `_imp__glewGetString@4'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0xb05): undefine
d reference to `glutDisplayFunc'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0xb11): undefine
d reference to `glutReshapeFunc'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0xb1d): undefine
d reference to `glutKeyboardFunc'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0xb29): undefine
d reference to `glutMouseFunc'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0xb35): undefine
d reference to `glutMotionFunc'
C:\Users\User1\AppData\Local\Temp\cc219WZV.o:mytest1.cpp:(.text+0xb3a): undefine
d reference to `glutMainLoop'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\U
ser1\AppData\Local\Temp\cc219WZV.o: bad reloc address 0x20 in section `.text$_ZS
t4sqrtf[__ZSt4sqrtf]'
collect2.exe: error: ld returned 1 exit status

EDIT2:lib文件夹的内容:

enter image description here

EDIT3:

体系结构:64位x64

编译器详细信息(g ++ -v):

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=m
ingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto
--enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++
,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-l
ibstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gm
p-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --
with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-
libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/
mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)

这些文件是从OpenGL的edx课程下载的。它使用了Visual Studio,但是我不能使用它,因为我的电脑很旧,并且我遇到了驱动程序问题,因此我试图从命令行编译所有内容。

我实际上花了5个小时来尝试获取OpenGl代码以使用g ++进行编译。我已经尝试了很多事情,甚至都不记得在这里发布。我想我的问题是将.libs和.dll与...

opengl dll g++ glut lib
1个回答
0
投票

[您告诉GCC在特定文件夹中查找库和标头,但没有告诉GCC实际上将库链接到输出二进制文件(想象一下,'lib'文件夹中有几GB的已编译库。GCC或任何其他C / C ++编译器都不会尝试链接所有库,因为其中某些库甚至可能不兼容或包含同一代码的多个副本。]

© www.soinside.com 2019 - 2024. All rights reserved.