c - 这个链接器错误(SDL2)是什么?

标签 c printf sdl-2

我有以下代码,目标是打开一个以毫秒为单位显示计时器的 SDL 窗口。所以我使用 SDLttf、SDL2 和 Getsystemtime() 来获取计时器。我收到这些链接器错误:

Error   3   error LNK2019: unresolved external symbol _snprintf referenced in function _SDL_main    ...\Source.obj PROJECT
Error   4   error LNK1120: 1 unresolved externals   PROJECT.exe PROJECT

代码:

#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
#include <SDL_ttf.h>
#include <windows.h>


int main(int argc, char ** argv)
{
    int quit = 0;
    SDL_Event event;
    char timertxt[1024];

    SDL_Init(SDL_INIT_VIDEO);
    TTF_Init();
    SYSTEMTIME st1, st2;

    GetSystemTime(&st1);

    SDL_Window * window = SDL_CreateWindow("SDL_ttf in SDL2",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 200,150, 0);
    SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0);

    TTF_Font * font = TTF_OpenFont("arial.ttf", 25);
    const char * error = TTF_GetError();
    SDL_Color color = { 255, 255, 255 };

    SDL_Surface * surface;
    SDL_Texture * texture;

    int texW = 0, texH = 0;
    SDL_Rect dstrect;

    while (!quit)
    {
        SDL_PollEvent(&event);
        SDL_Delay(1);

        switch (event.type)
        {
        case SDL_QUIT:
            quit = 1;
            break;
        }

        GetSystemTime(&st2);
        snprintf(timertxt, sizeof(timertxt), "%d", st1.wMilliseconds);
        surface = TTF_RenderText_Solid(font, timertxt, color);
        texture = SDL_CreateTextureFromSurface(renderer,surface);
        SDL_QueryTexture(texture, NULL, NULL, &texW, &texH);
        dstrect = (SDL_Rect){ 0, 0, texW, texH };

        SDL_RenderCopy(renderer, texture, NULL, &dstrect);
        SDL_RenderPresent(renderer);
    }

    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);
    TTF_CloseFont(font);

    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    TTF_Quit();
    SDL_Quit();

    return 0;
}

我不明白在 SME 代码中使用 snprintf 作为 SDL 有什么问题。

最佳答案

使用 _snprintf_snprintf_s 版本代替 snprintf。在 Windows 中,它被认为是已弃用的 POSIX 函数。

The following POSIX names for functions are deprecated. In most cases, prepending an underscore character gives the standard equivalent name.

检查此链接:

http://msdn.microsoft.com/en-us/library/ms235384%28v=vs.90%29.aspx

关于c - 这个链接器错误(SDL2)是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24989889/

相关文章:

c++ - 将系统命令的输出存储到 c 中的本地字符数组中

转换错误,IO C 程序

fork() 之前写入的内容在输出中出现两次

matlab - 在 Matlab 中将元胞数组打印为 .txt

c++ - 通过 printf 函数打印带有 %u 说明符的 unsigned char 是否安全?

c++ - SDL 导致 CEF3 产生额外的窗口

c++ - SDL2 绘制和填充形状

c - 在 Windows 10 上构建此代码的正确方法是什么?

opengl-es - 为什么我不能使用 SDL2 创建 OpenGL ES 3.0 上下文?

c - 最简单的RGB图像格式是什么?