我目前正在使用VisualStudioCode创建一个使用GLUT(#include "GL/glut.h"
中包含的图形)的游戏。但是,当我编译它时,
gcc main.c -o test
我面对的是
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x1c): undefined reference to `_imp____glutInitWithExit@12\
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x3f): undefined reference to `_imp____glutCreateWindowWithExit@8'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x61): undefined reference to `_imp____glutCreateMenuWithExit@8'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0xa77): undefined reference to `glBegin@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0xa90): undefined reference to `glColor3f@12'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0xb49): undefined reference to `glVertex2d@16'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0xb60): undefined reference to `glVertex2d@16'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0xb68): undefined reference to `glEnd@0'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x54a8): undefined reference to `glEnable@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x54bf): undefined reference to `glBlendFunc@8'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x55dc): undefined reference to `glClear@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x55eb): undefined reference to `glMatrixMode@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x55f3): undefined reference to `glLoadIdentity@0'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5609): undefined reference to `glScalef@12'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5634): undefined reference to `gluPerspective@32'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5643): undefined reference to `glMatrixMode@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x564b): undefined reference to `glLoadIdentity@0'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x568a): undefined reference to `gluLookAt@72'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x57d1): undefined reference to `glEnableClientState@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x57e0): undefined reference to `glEnableClientState@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5807): undefined reference to `glVertexPointer@16'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x582e): undefined reference to `glTexCoordPointer@16'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x584e): undefined reference to `glDrawArrays@12'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5875): undefined reference to `glVertexPointer@16'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x589c): undefined reference to `glTexCoordPointer@16'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x58bc): undefined reference to `glDrawArrays@12'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x58cb): undefined reference to `glDisable@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x58da): undefined reference to `glBegin@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x58f3): undefined reference to `glColor3f@12'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x590c): undefined reference to `glVertex3f@12'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5927): undefined reference to `glVertex3f@12'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5940): undefined reference to `glVertex3f@12'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x595b): undefined reference to `glVertex3f@12'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5974): undefined reference to `glColor3f@12'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x597c): undefined reference to `glEnd@0'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5988): undefined reference to `glEnable@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5990): undefined reference to `_imp__glutPostRedisplay@0'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5997): undefined reference to `_imp__glutSwapBuffers@0'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x599e): undefined reference to `glFlush@0'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x59f6): undefined reference to `_imp__glutSetCursor@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5a53): undefined reference to `_imp__glutSetCursor@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5b8c): undefined reference to `_imp__glutWarpPointer@8'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5bef): undefined reference to `_imp__glutGet@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5c05): undefined reference to `_imp__glutGet@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5ccd): undefined reference to `_imp__glutInitDisplayMode@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5ce6): undefined reference to `_imp__glutInitWindowSize@8'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5cff): undefined reference to `_imp__glutInitWindowPosition@8'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5d1f): undefined reference to `_imp__glutKeyboardFunc@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5d30): undefined reference to `_imp__glutKeyboardUpFunc@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5d41): undefined reference to `_imp__glutDisplayFunc@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5d52): undefined reference to `_imp__glutReshapeFunc@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5d63): undefined reference to `glEnable@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5d78): undefined reference to `glAlphaFunc@8'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5d87): undefined reference to `_imp__glutSetCursor@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5d98): undefined reference to `glEnable@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5db1): undefined reference to `_imp__glutPassiveMotionFunc@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5dc2): undefined reference to `_imp__glutMotionFunc@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5dd3): undefined reference to `_imp__glutMouseFunc@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5dec): undefined reference to `glPixelStorei@8'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5e03): undefined reference to `glGenTextures@8'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5e1b): undefined reference to `glBindTexture@8'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5e6f): undefined reference to `glTexImage2D@36'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5e90): undefined reference to `glTexParameterf@12'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5eb1): undefined reference to `glTexParameterf@12'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5ed2): undefined reference to `glTexParameterf@12'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5ef3): undefined reference to `glTexParameterf@12'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5f12): undefined reference to `glTexEnvi@12'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5f21): undefined reference to `glEnable@4'
C:\Users\playtech\AppData\Local\Temp\ccgUQvpv.o:main.c:(.text+0x5f29): undefined reference to `_imp__glutMainLoop@0'
collect2.exe: error: ld returned 1 exit status
在谷歌上搜索解决方案后,我也尝试了(-lglut,-lGLU 和 *-lgll * 的组合)
gcc main.c -o test -lglut
返回
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lGL
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lGLU
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lglut
然而,我已经在Mac上的Xcode中打开了这个文件,当愚者的终端命令遇到类似的Clang错误时,Xcode的内置“build”成功地创建了应用程序。
此外,我的代码使用了相当多的VLAs,C++对此不起作用,所以我真的很想让它在C中起作用。Visual Studio 2019也不喜欢构建我的解决方案,因为它不喜欢VLA。
当愚者包含GLUT时,我如何让愚者编译这个文件?
如何编译包含GLUT的C文件?
1条答案
按热度按时间bqf10yzr1#
您需要添加-L〈Directory name〉来告诉编译器在哪里可以找到您想要链接的库(GLUT、GLU和GL),因为在标准目录列表中找不到它们。
参考愚者官方文件:Options for Linking
-llibrary -l library在链接时搜索名为library的库。(将库作为单独参数的第二种方法仅用于POSIX兼容性,不建议使用。)
-l选项由愚者直接传递给链接器。请参考您的链接器文档以获得确切的细节。下面的一般描述适用于GNU链接器。
连接器会在标准目录清单中搜寻程式库。搜寻的目录包括数个标准系统目录以及您以-L指定的任何目录。
现有的问题和答案将提供一个明确的例子:***