1

我一直在疯狂地试图找出这里的问题。我的项目在 Fedora 上构建良好,带有原生 gcc 和 pkg-config 标志,但是当在 Windows 上交叉编译或使用 MingW 时,它给了我未定义的引用。最奇怪的是,我记得让它在 Windows 上编译一次或两次,但我不知道如何编译。据我所知,所有的库都可以访问,所以我不知道出了什么问题。

使用此输入:

mingw32-gcc -std=c99 -g -LC:/MinGW/lib -mwindows -lSDL -lSDLmain  -lfreetype -lmingw32 -lglu32 -lopengl32 -o bin/gltris.exe gltris.o graphics.o input.o game.o block.o timer.o text.o 

我得到了这个输出:(对不起,奇怪的格式)


C:/MinGW/lib/libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `WinMain@16'
gltris.o: In function `gltris_init':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/gltris.c:24: undefined reference to `SDL_Init'
gltris.o: In function `SDL_main':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/gltris.c:110: undefined reference to `SDL_Quit'
graphics.o: In function `graphics_init':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:31: undefined reference to `SDL_SetVideoMode'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:34: undefined reference to `glClearColor@16'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:35: undefined reference to `glClear@4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:36: undefined reference to `glViewport@16'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:38: undefined reference to `glMatrixMode@4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:39: undefined reference to `glLoadIdentity@0'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:40: undefined reference to `glDisable@4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:41: undefined reference to `glBlendFunc@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:42: undefined reference to `glPixelStorei@8'
graphics.o: In function `graphics_begin_frame':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:50: undefined reference to `glMatrixMode@4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:51: undefined reference to `glLoadIdentity@0'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:52: undefined reference to `glClear@4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:54: undefined reference to `gluOrtho2D@32'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:56: undefined reference to `glMatrixMode@4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:57: undefined reference to `glLoadIdentity@0'
graphics.o: In function `graphics_end_frame':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:62: undefined reference to `SDL_GL_SwapBuffers'
graphics.o: In function `graphics_render_block':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:68: undefined reference to `glPushMatrix@0'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:70: undefined reference to `glTranslatef@12'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:71: undefined reference to `glScalef@12'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:74: undefined reference to `glColor4ub@16'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:76: undefined reference to `glColor3ubv@4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:78: undefined reference to `glEnable@4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:81: undefined reference to `glBegin@4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:82: undefined reference to `glVertex2i@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:83: undefined reference to `glVertex2i@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:84: undefined reference to `glVertex2i@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:85: undefined reference to `glVertex2i@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:86: undefined reference to `glEnd@0'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:88: undefined reference to `glDisable@4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:90: undefined reference to `glPopMatrix@0'
graphics.o: In function `render_textured_quad':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:165: undefined reference to `glPushMatrix@0'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:167: undefined reference to `glEnable@4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:168: undefined reference to `glEnable@4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:169: undefined reference to `glBindTexture@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:171: undefined reference to `glTranslatef@12'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:173: undefined reference to `glBegin@4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:175: undefined reference to `glTexCoord2f@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:176: undefined reference to `glVertex2f@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:178: undefined reference to `glTexCoord2f@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:179: undefined reference to `glVertex2f@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:181: undefined reference to `glTexCoord2f@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:182: undefined reference to `glVertex2f@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:184: undefined reference to `glTexCoord2f@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:185: undefined reference to `glVertex2f@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:187: undefined reference to `glEnd@0'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:189: undefined reference to `glDisable@4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:190: undefined reference to `glDisable@4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:192: undefined reference to `glPopMatrix@0'
graphics.o: In function `surface_to_texture':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:212: undefined reference to `glGenTextures@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:213: undefined reference to `glBindTexture@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:214: undefined reference to `glTexParameteri@12'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:215: undefined reference to `glTexParameteri@12'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:216: undefined reference to `glTexImage2D@36'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:221: undefined reference to `SDL_FreeSurface'
input.o: In function `handle_input':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/input.c:13: undefined reference to `SDL_PollEvent'
timer.o: In function `add_timer':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/timer.c:20: undefined reference to `SDL_GetTicks'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/timer.c:36: undefined reference to `SDL_GetTicks'
timer.o: In function `do_timers':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/timer.c:65: undefined reference to `SDL_GetTicks'
timer.o: In function `pause_timer':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/timer.c:84: undefined reference to `SDL_GetTicks'
timer.o: In function `resume_timer':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/timer.c:90: undefined reference to `SDL_GetTicks'
timer.o:C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/timer.c:98: more undefined references to `SDL_GetTicks' follow
text.o: In function `text_init':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:24: undefined reference to `_imp__FT_Init_FreeType'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:28: undefined reference to `_imp__FT_New_Face'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:32: undefined reference to `_imp__FT_Set_Char_Size'
text.o: In function `text_gen_texture':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:70: undefined reference to `glGenTextures@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:71: undefined reference to `glBindTexture@8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:72: undefined reference to `glTexParameteri@12'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:73: undefined reference to `glTexParameteri@12'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:77: undefined reference to `glTexImage2D@36'
text.o: In function `text_print':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:92: undefined reference to `_imp__FT_Set_Char_Size'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:97: undefined reference to `_imp__FT_Load_Char'
text.o: In function `get_text_size':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:115: undefined reference to `_imp__FT_Set_Char_Size'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:119: undefined reference to `_imp__FT_Load_Char'
text.o: In function `print_game_info':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:138: undefined reference to `glColor3f@12'
collect2.exe: error: ld returned 1 exit status

编辑:我通过一次编译和链接来构建它,使用链接器标志“-lmingw32 -lopengl32 -lSDLmain -lSDL -lfreetype -mwindows”

4

1 回答 1

0

您的编译器似乎找不到 libSDL.a 和其他库文件。检查 libSDL.a 是否存在于 C:/MinGW/lib 中。您将需要一个专门为 mingw 制作的 libSDL.a。

另外,尝试编译一个简单的“Hello World”SDL 程序。这将更容易找到错误所在。

于 2013-06-07T04:21:23.923 回答