0

I am using c, sdl2 and raycasting to create a maze from a 2d array:

// 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;
            }

        }
    }
    
}

then I compiled:

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

...but got an error I cannot understand:

//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

I am using an ubuntu14.04.6 (required by task description) virtual machine on windows 10 if it is helpfull.

here is my complete code https://github.com/Blackysynch/Maze1.0/tree/moving

genpfault
  • 51,148
  • 11
  • 85
  • 139
Ornelle
  • 1
  • 1
  • try linking to the math library, i.e. add '-lm' to your command line. Try using: "gcc -Wall -Wextra -Werror -pedantic main.h main.c sdl.c raycast.c input.c -lSDL2 -lm -o movement" – thurizas Aug 24 '23 at 10:41
  • thanks I linked it and it compiled. Now I am back to debugging since I am getting segmentation fault(core dumped) message – Ornelle Aug 24 '23 at 14:42

0 Answers0