gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 07:15:36 25 4
gpt4 key购买 nike

我有以下代码,目标是打开一个以毫秒为单位显示计时器的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com