SDL_GetTicks() 定义缺失。 (SDL 2.0.3)

Posted

技术标签:

【中文标题】SDL_GetTicks() 定义缺失。 (SDL 2.0.3)【英文标题】:SDL_GetTicks() Definition Missing. (SDL 2.0.3) 【发布时间】:2014-07-25 16:35:12 【问题描述】:

我在编译我不久前编写的程序时遇到了问题(当我使用 SDL 1.2 时)。 缺少许多定义:

SDL_GetTicks() SDL_FillRect() SDL_SetVideoMode() SDL_DisplayFormatAlpha()

还有更多。

这些是我包含的标题:

#include <SDL.h>
#include "fractile.h"
#include "graphics.h"
#include "globals.h"
#include "math.h"
#include "math_custom.h"
#include "Windows.h"
#include <stdio.h>

这是构建日志

-------------- Build: Debug in Fractile (compiler: GNU GCC Compiler)---------------

mingw32-gcc.exe -Wall -Wall -g -IC:\Users\ryjensen\Programs\SDL\SDL2-2.0.3\x86_64-w64-mingw32\include\SDL2 -IC:\Users\ryjensen\Programs\SDL\SDL2_ttf-2.0.12\x86_64-w64-mingw32\include\SDL2\ -IC:\Users\ryjensen\Programs\SDL\SDL2_image-2.0.0\x86_64-w64-mingw32\include\SDL2\ -c C:\Users\ryjensen\Programs\Fractile\fractile.c -o obj\Debug\fractile.o
C:\Users\ryjensen\Programs\Fractile\fractile.c: In function 'fractal_editor':
C:\Users\ryjensen\Programs\Fractile\fractile.c:366:4: warning: implicit declaration of function 'within_rect' [-Wimplicit-function-declaration]
mingw32-g++.exe -LC:\Users\ryjensen\Programs\SDL\SDL2-2.0.3\x86_64-w64-mingw32\lib -LC:\Users\ryjensen\Programs\SDL\SDL2_ttf-2.0.12\x86_64-w64-mingw32\lib -LC:\Users\ryjensen\Programs\SDL\SDL2_image-2.0.0\x86_64-w64-mingw32\lib -o bin\Debug\Fractile.exe obj\Debug\fractile.o obj\Debug\general_functions.o obj\Debug\graphics.o obj\Debug\main.o obj\Debug\math_custom.o  -lcomdlg32 -lmingw32 -lSDL2 -lSDL2_image -lSDL2_ttf -lmingw32 -lSDL2 -lSDL2_image -lSDL2_ttf   -mwindows
obj\Debug\fractile.o: In function `fractal_wobble':
C:/Users/ryjensen/Programs/Fractile/fractile.c:197: undefined reference to `SDL_GetTicks'
C:/Users/ryjensen/Programs/Fractile/fractile.c:207: undefined reference to `SDL_GetTicks'
obj\Debug\fractile.o: In function `fractal_editor':
C:/Users/ryjensen/Programs/Fractile/fractile.c:424: undefined reference to `SDL_FillRect'
C:/Users/ryjensen/Programs/Fractile/fractile.c:440: undefined reference to `SDL_FillRect'
C:/Users/ryjensen/Programs/Fractile/fractile.c:446: undefined reference to `SDL_FillRect'
C:/Users/ryjensen/Programs/Fractile/fractile.c:464: undefined reference to `SDL_FillRect'
obj\Debug\general_functions.o: In function `set_window_size':
C:/Users/ryjensen/Programs/Fractile/general_functions.c:82: undefined reference to `SDL_SetVideoMode'
obj\Debug\general_functions.o: In function `load_image':
C:/Users/ryjensen/Programs/Fractile/general_functions.c:102: undefined reference to `IMG_Load'
C:/Users/ryjensen/Programs/Fractile/general_functions.c:108: undefined reference to `SDL_DisplayFormatAlpha'
C:/Users/ryjensen/Programs/Fractile/general_functions.c:112: undefined reference to `SDL_FreeSurface'
obj\Debug\general_functions.o: In function `create_surface':
C:/Users/ryjensen/Programs/Fractile/general_functions.c:128: undefined reference to `SDL_CreateRGBSurface'
C:/Users/ryjensen/Programs/Fractile/general_functions.c:136: undefined reference to `SDL_DisplayFormatAlpha'
C:/Users/ryjensen/Programs/Fractile/general_functions.c:138: undefined reference to `SDL_FreeSurface'
obj\Debug\general_functions.o: In function `init':
C:/Users/ryjensen/Programs/Fractile/general_functions.c:144: undefined reference to `SDL_Init'
C:/Users/ryjensen/Programs/Fractile/general_functions.c:157: undefined reference to `SDL_WM_SetCaption'
obj\Debug\general_functions.o: In function `load_files':
C:/Users/ryjensen/Programs/Fractile/general_functions.c:181: undefined reference to `TTF_Init'
C:/Users/ryjensen/Programs/Fractile/general_functions.c:189: undefined reference to `TTF_OpenFont'
C:/Users/ryjensen/Programs/Fractile/general_functions.c:190: undefined reference to `TTF_OpenFont'
obj\Debug\general_functions.o: In function `clean_up':
C:/Users/ryjensen/Programs/Fractile/general_functions.c:207: undefined reference to `SDL_FreeSurface'
C:/Users/ryjensen/Programs/Fractile/general_functions.c:211: undefined reference to `SDL_Quit'
C:/Users/ryjensen/Programs/Fractile/general_functions.c:212: undefined reference to `TTF_Quit'
obj\Debug\general_functions.o: In function `print_red_box':
C:/Users/ryjensen/Programs/Fractile/general_functions.c:262: undefined reference to `SDL_FillRect'
obj\Debug\graphics.o: In function `apply_surface':
C:/Users/ryjensen/Programs/Fractile/graphics.c:55: undefined reference to `SDL_UpperBlit'
obj\Debug\graphics.o: In function `apply_text':
C:/Users/ryjensen/Programs/Fractile/graphics.c:64: undefined reference to `TTF_RenderText_Blended'
C:/Users/ryjensen/Programs/Fractile/graphics.c:69: undefined reference to `SDL_FreeSurface'
obj\Debug\graphics.o: In function `apply_surface_clips':
C:/Users/ryjensen/Programs/Fractile/graphics.c:84: undefined reference to `SDL_UpperBlit'
obj\Debug\graphics.o: In function `apply_outline':
C:/Users/ryjensen/Programs/Fractile/graphics.c:98: undefined reference to `SDL_FillRect'
C:/Users/ryjensen/Programs/Fractile/graphics.c:102: undefined reference to `SDL_FillRect'
C:/Users/ryjensen/Programs/Fractile/graphics.c:109: undefined reference to `SDL_FillRect'
C:/Users/ryjensen/Programs/Fractile/graphics.c:113: undefined reference to `SDL_FillRect'
obj\Debug\graphics.o: In function `gradient':
C:/Users/ryjensen/Programs/Fractile/graphics.c:172: undefined reference to `SDL_FillRect'
obj\Debug\graphics.o:C:/Users/ryjensen/Programs/Fractile/graphics.c:195: more undefined references to `SDL_FillRect' follow
obj\Debug\main.o: In function `SDL_main':
C:/Users/ryjensen/Programs/Fractile/main.c:83: undefined reference to `SDL_PollEvent'
C:/Users/ryjensen/Programs/Fractile/main.c:240: undefined reference to `SDL_Flip'
C:/Users/ryjensen/Programs/Fractile/main.c:241: undefined reference to `SDL_FillRect'
C:/Users/ryjensen/Programs/Fractile/main.c:246: undefined reference to `SDL_GetTicks'
c:/users/ryjensen/programs/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 2 second(s))
37 error(s), 1 warning(s) (0 minute(s), 2 second(s))

这是我项目中的一些相关代码:

void fractal_wobble(struct fractalData *f, int wobbleEvent)
    int i;

    if(wobbleEvent==vw_evaluate)
        double wobbleAngle;
        for(i=0; i<f->numbVectors; i++)
            if(f->vects[i].period > 0)
                wobbleAngle = (2*PI*(SDL_GetTicks() - f->vects[i].wobbleStartTime))/f->vects[i].period;
                f->exits[i].x = f->vects[i].x = f->vects[i].xorig*(1.0 + f->vects[i].xWobble*cos(wobbleAngle));
                f->exits[i].y = f->vects[i].y = f->vects[i].yorig*(1.0 + f->vects[i].yWobble*sin(wobbleAngle));
            
        
    


    if(wobbleEvent==vw_toggle)
        if(f->vects[currentVector].period == 0)
            f->vects[currentVector].wobbleStartTime = SDL_GetTicks();
            f->vects[currentVector].period = WOBBLE_DEFAULT_PERIOD;
            f->vects[currentVector].xorig = f->vects[currentVector].x;
            f->vects[currentVector].yorig = f->vects[currentVector].y;
            f->vects[currentVector].xWobble = WOBBLE_PERCENTAGE_OF_MAGNITUDE;
            f->vects[currentVector].yWobble = WOBBLE_PERCENTAGE_OF_MAGNITUDE;
        
        else
            f->vects[currentVector].period = 0;
            f->exits[currentVector].x = f->vects[currentVector].x = f->vects[currentVector].xorig;
            f->exits[currentVector].y = f->vects[currentVector].y = f->vects[currentVector].yorig;

    

我一定错过了一些非常简单的东西。

我已经更新了所有的 include 和 lib 目录。 我已更新工作目录中的所有 .dll 文件。 我也更新了所有链接器设置。

如果我自己能解决,我会用我的解决方案更新这篇文章。

【问题讨论】:

【参考方案1】:

我刚刚弄清楚为什么它没有编译。我正在链接到 64 位标头/库。

这正是我为使 SDL 正常工作所做的工作:

使用以下链接器设置: -lmingw32 -lSDL2main -lSDL2 -lwinmm

搜索目录:

编译器

C:\Users\USERNAME\Programs\SDL\SDL2-2.0.3\i686-w64-mingw32\include\SDL2

C:\Users\USERNAME\Programs\SDL\SDL2_ttf-2.0.12\i686-w64-mingw32\include\SDL2

C:\Users\USERNAME\Programs\SDL\SDL2_image-2.0.0\i686-w64-mingw32\include\SDL2

链接器

C:\Users\USERNAME\Programs\SDL\SDL2-2.0.3\i686-w64-mingw32\lib

C:\Users\USERNAME\Programs\SDL\SDL2_ttf-2.0.12\i686-w64-mingw32\lib

C:\Users\USERNAME\Programs\SDL\SDL2_image-2.0.0\i686-w64-mingw32\lib

确保为 32 位编译选择了“i686-w64-mingw32”文件夹。 “x86_64-w64-mingw32”文件夹用于64位编译

测试程序: #包括 #包括

int main(int argc, char *argv[])


    return 0;

你应该能够编译这个。 这将允许您确保您的链接器/编译器设置是正确的,并且一切都在它应该在的位置。

干杯, 詹森

【讨论】:

【参考方案2】:

您不能只将 SDL 从 1.x 更新到 2.x。这里没有向后兼容性。删除了一些旧功能,添加了一些新功能。

顺便说一句,您可以在 wiki 上找到“迁移指南”(从 1.x 到 2.x)。

【讨论】:

我一直在查看该迁移指南,但它并没有解决我的所有问题。我看到我将不得不重新处理我的很多表面材料和屏幕函数,但看起来我想要使用的函数(即 SDL_FillRect() 和 SDL_GetTicks())仍然存在于 SDL 2 中. 我一直在阅读 SDL 2 wiki 和 these functions are still listed there 哦。也许,您以错误的方式链接 SDL。您使用的是什么编译器和设置? 你是对的。我发布了一个答案,解释了我做错了什么。

以上是关于SDL_GetTicks() 定义缺失。 (SDL 2.0.3)的主要内容,如果未能解决你的问题,请参考以下文章

SDL 帧速率上限实施

chaos;head移植版缺失python27.dll SDL2.dll问题解决

为啥 SDL 定义主宏?

SDL1 -> 使用自定义屏幕模式类构建 SDL2 分辨率列表

使用 CMake 对 SDL 的未定义引用

SDL2 丢失 OpenGL 上下文或未定义函数