Author Topic: undefined reference to /usr/local/lib/libSDL2_ttf.so undefined reference to `S  (Read 221 times)

Offline Rahul

  • Multiple posting newcomer
  • *
  • Posts: 16
hi to all, I've centos7.5 in VM. I am trying to compile to SDL program. but having following problem :-
Code: [Select]
/usr/local/lib/libSDL2_ttf.so||undefined reference to `SDL_RWseek'|
/usr/local/lib/libSDL2_ttf.so||undefined reference to `SDL_RWclose'|
/usr/local/lib/libSDL2_ttf.so||undefined reference to `SDL_RWtell'|
/usr/local/lib/libSDL2_ttf.so||undefined reference to `SDL_RWsize'|
/usr/local/lib/libSDL2_ttf.so||undefined reference to `SDL_RWread'|
||error: ld returned 1 exit status|
source code is :-
Code: [Select]
#include <SDL.h>
#include <SDL/SDL_image.h>
#include <SDL_ttf.h>

#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::endl;


int main(int argc, char ** argv)
{

    SDL_Texture *currentImagetexture = nullptr;
    SDL_Surface * currentImage = nullptr;
    SDL_Renderer *renderer = nullptr;
    SDL_Window * sdlWindow = nullptr;
    SDL_Surface *windowsurface = SDL_GetWindowSurface(sdlWindow);

    if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
    {
        std ::cout <<"Error in ...  if(SDL_Init(SDL_INIT_EVERYTHING) <0) : " << SDL_GetError() << endl;
    }

    if((sdlWindow = SDL_CreateWindow("Game engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,1024, 768, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL)) < 0)
    {
        std ::cout <<"Error in ... sdlWindow = SDL_CreateWindow : "<<  SDL_GetError() << endl;
        exit(2);
    }

    if(TTF_Init() < 0 )
    {
        cout << " Error ... TTF_Init() < 0 ) " << TTF_GetError() << endl;
        exit(4);
    }

    windowsurface = SDL_GetWindowSurface(sdlWindow);

    renderer = SDL_CreateRenderer(sdlWindow,-1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

    SDL_Event *ev = new SDL_Event;

    TTF_Font *font = TTF_OpenFont("Roboto-Black.ttf",20);
    SDL_Color color = {0,0,0,255};
    SDL_Surface *text_surface = TTF_RenderText_Solid(font, "rahul", color);
    SDL_Texture * text = SDL_CreateTextureFromSurface(renderer, windowsurface);

    SDL_Rect rect;
    rect.x = rect.y =0;

    SDL_QueryTexture(text, NULL, NULL,&rect.w, &rect.h);

    bool isRunning = true;

    while(isRunning)
    {
        while (SDL_PollEvent(ev))
        {
            if(ev->type == SDL_QUIT)
            {
                isRunning = false;
            }

        }
        SDL_RenderClear(renderer);
        SDL_RenderCopy(renderer, text, NULL, &rect);
        SDL_RenderPresent(renderer);
    }


    SDL_FreeSurface(windowsurface);
    SDL_FreeSurface(currentImage);

    SDL_DestroyRenderer(renderer);

    SDL_DestroyTexture(currentImagetexture);
    SDL_DestroyWindow(sdlWindow);

    windowsurface = nullptr;
    currentImage = nullptr;
sdlWindow = nullptr;
    SDL_Quit();

    return 0;
}
haow to get solved these errors