gpt4 book ai didi

c - SDL2 libSDL2_image.so : undefined reference to

转载 作者:行者123 更新时间:2023-11-30 20:57:52 30 4
gpt4 key购买 nike

我使用的是 Kubuntu 18.04

所以我最近尝试使用 SDL2,我想创建一个简单的窗口,在教程之后显示一些图片,但我无法编译示例代码。

当我尝试编译代码时,我得到:

/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libSDL2_image.so: undefined reference to `SDL_ceilf'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libSDL2_image.so: undefined reference to `SDL_acosf'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libSDL2_image.so: undefined reference to `SDL_floorf'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libSDL2_image.so: undefined reference to `SDL_fabsf'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libSDL2_image.so: undefined reference to `SDL_LoadFile_RW'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libSDL2_image.so: undefined reference to `SDL_fmodf'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libSDL2_image.so: undefined reference to `SDL_atan2f'
collect2: error: ld returned 1 exit status

使用的命令:

gcc SDLProject.c -o SDLProject `sdl2-config --cflags --libs` -lSDL2_gfx -lSDL2_image

用于安装 SDL2 库的命令:

sudo apt install libsdl2-dev libsdl2-gfx-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-mixer-dev

已安装的软件包:

sudo apt list --installed | grep "sdl"

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libsdl2-2.0-0/bionic-updates,now 2.0.8+dfsg1-1ubuntu1.18.04.3 amd64 [installed]
libsdl2-dev/bionic-updates,now 2.0.8+dfsg1-1ubuntu1.18.04.3 amd64 [installed]
libsdl2-gfx-1.0-0/bionic,now 1.0.4+dfsg-1 amd64 [installed,automatic]
libsdl2-gfx-dev/bionic,now 1.0.4+dfsg-1 amd64 [installed]
libsdl2-image-2.0-0/bionic,now 2.0.3+dfsg1-1 amd64 [installed,automatic]
libsdl2-image-dev/bionic,now 2.0.3+dfsg1-1 amd64 [installed]
libsdl2-mixer-2.0-0/bionic,now 2.0.2+dfsg1-2 amd64 [installed,automatic]
libsdl2-mixer-dev/bionic,now 2.0.2+dfsg1-2 amd64 [installed]
libsdl2-ttf-2.0-0/bionic,now 2.0.14+dfsg1-2 amd64 [installed,automatic]
libsdl2-ttf-dev/bionic,now 2.0.14+dfsg1-2 amd64 [installed]

我已经尝试删除与 SDL/SDL2 相关的所有内容,只重新安装项目使用的内容(SDL2、gfx 和图像),我发现只有当我尝试包含 SDL_image 时才会发生此错误。 h,我可以运行其他不使用它的 exmaple 代码。

我认为该错误与代码本身无关,但是:

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL2_gfxPrimitives.h>
#include <stdlib.h>

typedef enum Babu {
VKiraly, VVezer, VBastya, VFuto, VHuszar, VGyalog,
SKiraly, SVezer, SSastya, SFuto, SHuszar, SGyalog
} Babu;

enum { MERET = 52 };


void babu_rajzol(SDL_Renderer *renderer, SDL_Texture *babuk, Babu melyik, int x, int y) {

SDL_Rect src = { (melyik % 6) * 62 + 10, (melyik / 6) * 60 + 10, MERET, MERET };
SDL_Rect dest = { x, y, MERET, MERET };
SDL_RenderCopy(renderer, babuk, &src, &dest);
}


void sdl_init(int szeles, int magas, SDL_Window **pwindow, SDL_Renderer **prenderer) {
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
SDL_Log("Nem indithato az SDL: %s", SDL_GetError());
exit(1);
}
SDL_Window *window = SDL_CreateWindow("SDL peldaprogram", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, szeles, magas, 0);
if (window == NULL) {
SDL_Log("Nem hozhato letre az ablak: %s", SDL_GetError());
exit(1);
}
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
if (renderer == NULL) {
SDL_Log("Nem hozhato letre a megjelenito: %s", SDL_GetError());
exit(1);
}
SDL_RenderClear(renderer);

*pwindow = window;
*prenderer = renderer;
}


int main(int argc, char *argv[]) {
SDL_Window *window;
SDL_Renderer *renderer;
sdl_init(320, 200, &window, &renderer);

SDL_Texture *babuk = IMG_LoadTexture(renderer, "pieces.png");
if (babuk == NULL) {
SDL_Log("Nem nyithato meg a kepfajl: %s", IMG_GetError());
exit(1);
}

boxRGBA(renderer, 0, 0, 319, 199, 0x90, 0xE0, 0x90, 0xFF);
babu_rajzol(renderer, babuk, VKiraly, 82, 74);
babu_rajzol(renderer, babuk, SGyalog, 82+MERET, 74);
babu_rajzol(renderer, babuk, VHuszar, 82+2*MERET, 74);
SDL_RenderPresent(renderer);

SDL_DestroyTexture(babuk);

SDL_Event event;
while (SDL_WaitEvent(&event) && event.type != SDL_QUIT) {
}

SDL_Quit();
return 0;
}

最佳答案

您没有获得包含sdl-config的sdl包。您可以从

获取它
sudo apt install libsdl1.2-dev

关于c - SDL2 libSDL2_image.so : undefined reference to,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55984621/

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