SDL 的“未定义符号引用”?

"undefined reference to symbol" with SDL?

提问人:Ornelle 提问时间:8/24/2023 最后编辑:genpfaultOrnelle 更新时间:8/24/2023 访问量:43

问:

我正在使用 c、sdl2 和光线投射从 2d 数组创建迷宫:

// input.c
#include <SDL2/SDL.h>
#include "main.h"
#include <stdlib.h>

void move(double dirX, double dirY, double planeX, double planeY, double posX, double posY, double time, double oldTime, SDL_Event e)
{
    double oldDirX;
    double oldPlaneX;
    double frameTime;/*time the frame took*/
    double moveSpeed;
    double rotSpeed;
    
    oldTime = time;
    time = SDL_GetTicks();
    frameTime = (time - oldTime) / 1000.0;
    printf("%f", 1.0 / frameTime); /*FPS counter*/
    /*redraw();
     * cls();
     * */
    moveSpeed = frameTime * 5.0;
    rotSpeed = frameTime * 3.0;

    while (SDL_PollEvent( &e ) != 0)
    {
        /*
        if (e.type == SDL_QUIT)
        {
            quit = true;
        }
        */

        /**keyboard press events*/

        if (e.type == SDL_KEYDOWN)
        {
            switch (e.key.keysym.sym)
            {
                case SDLK_LEFT:
                    oldDirX = dirX;
                    dirX = dirX * cos(rotSpeed) - dirY * sin(rotSpeed);
                    dirY = oldDirX * sin(rotSpeed) + dirY * cos(rotSpeed);
                    oldPlaneX = planeX;
                    planeX = planeX * cos(rotSpeed) - planeY * sin(rotSpeed);
                    planeY = oldPlaneX * sin(rotSpeed) + planeY * cos(rotSpeed);
                    break;
                case SDLK_RIGHT:
                    oldDirX = dirX;
                    dirX = dirX * cos(-rotSpeed) - dirY * sin(-rotSpeed);
                    dirY = oldDirX * sin(-rotSpeed) + dirY * cos(-rotSpeed);
                    oldPlaneX = planeX;
                    planeX = planeX * cos(-rotSpeed) - planeY * sin(-rotSpeed);
                    planeY = oldPlaneX * sin(-rotSpeed) + planeY * cos(-rotSpeed);
                    break;
                case SDLK_UP:
                    if (worldMap[(int)(posX + dirX * moveSpeed)][(int)posY] == false)
                        posX += dirX * moveSpeed;
                    if (worldMap[(int)posX][(int)(posY + dirY * moveSpeed)] == false)
                         posY += dirY * moveSpeed;
                    break;
                case SDLK_DOWN:
                    if (worldMap[(int)(posX - dirX * moveSpeed)][(int)posY] == false)
                        posX -= dirX * moveSpeed;
                    if (worldMap[(int)posX][(int)(posY - dirY * moveSpeed)] == false)
                        posY -= dirY * moveSpeed;
                    break;
            }

        }
    }
    
}

然后我编译:

gcc -Wall -Wextra -Werror -pedantic main.h main.c sdl.c raycast.c input.c -lSDL2 -o movement

...但是有一个我无法理解的错误:

//usr/bin/ld: /tmp/ccqHKhlh.o: undefined reference to symbol 'cos@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

如果有帮助,我在 Windows 10 上使用 ubuntu14.04.6(任务描述需要)虚拟机。

这是我的完整代码 https://github.com/Blackysynch/Maze1.0/tree/moving

C GCC SDL-2 未定义参考 光线投射

评论


答: 暂无答案