在MinGW下无法编译SDL / OpenGL程序

时间:2018-09-15 14:47:38

标签: mingw sdl-2 mingw32

我很难制作用于Windows(使用MinGW)的示例SDL / OpenGL程序。它在运行Arch的虚拟机中编译时没有错误(尽管有警告)。问题似乎在链接阶段。它死于许多“对symbol的未定义引用”错误。我正在使用以下命令行进行编译:

gcc -L/mingw32/lib -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lglu32 -mwindows -I/mingw32/include/SDL2 -Dmain=SDL_main -o cube -3 cube-3.c

我从中运行命令的终端是32位的,因此库与体系结构类型匹配。我检查了所有被引用的库是否都安装在适当的位置

/mingw32/i686-w64-mingw32/lib/libopengl32.a
/mingw32/i686-w64-mingw32/lib/libglu32.a
/mingw32/lib/libSDL2.a
/mingw32/lib/libSDL2main.a
/mingw32/lib/libSDL2.dll.a

链接器错误都是这种形式:

C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: C:\msys64\tmp\ccuBYqiv.o:cube-3.c:(.text+0x37): undefined reference to `SDL_RWFromFile

无法解析的符号

SDL_RWFromFile
SDL_LoadBMP_RW
_imp__glGenTextures@8
_imp__glBindTexture@8
_imp__glTexImage2D@36
_imp__glTexParameteri@12
_imp__glTexParameteri@12
SDL_FreeSurface
SDL_Init
SDL_GetError
SDL_GL_SetAttribute
SDL_GL_SetAttribute
SDL_CreateWindow
SDL_GetError
SDL_GL_CreateContext
SDL_GetError
SDL_GL_SetSwapInterval
_imp__glEnable@4
_imp__glDepthFunc@4
glGenBuffers
glBindBuffer
glBufferData
glGenVertexArrays
glBindVertexArray
glEnableVertexAttribArray
glVertexAttribPointer
glCreateShader
glShaderSource
glCompileShader
glCreateShader
glShaderSource
glCompileShader
glCreateProgram
glAttachShader
glAttachShader
glLinkProgram
_imp__glEnable@4
_imp__glShadeModel@4
_imp__glClearColor@16
_imp__glClearDepth@8
_imp__glEnable@4
_imp__glDepthFunc@4
_imp__glHint@8
_imp__glLoadIdentity@0
_imp__glTranslatef@12
_imp__glRotatef@16
_imp__glBegin@4
_imp__glColor3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glColor3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glColor3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glColor3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glColor3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glColor3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glVertex3f@12
_imp__glEnd@0
_imp__glBegin@4
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glTexCoord2f@8
_imp__glVertex3f@12
_imp__glEnd@0
_imp__glClear@4
glUseProgram
glBindVertexArray
_imp__glDrawArrays@12
SDL_DestroyWindow
SDL_Quit
SDL_StartTextInput
SDL_GetMouseState
SDL_PollEvent
SDL_GL_SwapWindow
SDL_StopTextInput
collect2.exe: error: ld returned 1 exit status

更新---这些是按此顺序包含的标头

#include <SDL.h>
 #include <SDL_opengl.h>
 #include <GL/glu.h>
 #include <GL/gl.h>

 #include <pthread.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <time.h>

1 个答案:

答案 0 :(得分:0)

正如keltar在注释中指出的那样,gcc的参数顺序是错误的。将其更改为

debug = true
logLevel = "ERROR"
defaultEntryPoints = ["http","https"]

[entryPoints]
  [entryPoints.http]
  address = ":80"
  [entryPoints.https]
  address = ":443"
  [entryPoints.https.tls]
    [[entryPoints.https.tls.certificates]]
      certFile = "/sslcert/*.mydomain.com.crt"
      keyFile = "/sslcert/*.mydomain.com.key"

[retry]

请注意,不仅import java.util.*; import java.io.*; import java.lang.Integer; public class Solution{ public static void main(String []argh) { Scanner sc = new Scanner(System.in); long t=sc.nextInt(); for(int i=0;i<t;i++) { try { long x=sc.nextLong(); System.out.println(x+" can be fitted in:"); if(x>=0x81 || x<=0x7f)System.out.println("* byte"); if(x<=0x7fff || x>=0x8001)System.out.println("* short"); if(x<=0x7fffffff || x>=0x80000001)System.out.println("* int"); //if(x<= (0x7fffffffffffffff)|| x>= //(0x8000000000000001))System.out.println("*long"); System.out.printf("\n\n%x\n\n",x); System.out.println(); } catch(Exception e) { System.out.println(sc.next()+" can't be fitted anywhere."); } } } } 部分被移到开头,而且gcc -o cube-3 cube-3.c -L/mingw32/lib -lmingw32 -lSDL2main -lSDL2 -lglew32 -opengl32 -lglu32 -mwindows -I/mingw32/include/ SDL2 -Dmain=SDL_main 也被添加到-o cube-3 cube-3.c之前(以及SDL内容之后)。源文件需要引用GL / glew.h

lglew32