Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6374095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:26:44+00:00 2026-05-25T01:26:44+00:00

The following code is pretty simple. It just draws an image to the screen

  • 0

The following code is pretty simple. It just draws an image to the screen with a background using SDL. The program I was able to run before hand did fine, referencing everything without a problem.

Now, however, the compiler complains.

Anyway, here’s the code:

#include <iostream>
#include <string>
#include "SDL/SDL.h"

const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

using std::string;

SDL_Surface * load_image(std::string filename)
{
    SDL_Surface * loadedImage = NULL;

    SDL_Surface * optimizedImage = NULL;

    loadedImage = SDL_LoadBMP(filename.c_str());

    if (loadedImage != NULL)
    {
        optimizedImage = SDL_DisplayFormat(loadedImage);

        SDL_FreeSurface(loadedImage);
    }

    return optimizedImage;
}

void apply_surface(int x, int y, SDL_Surface * source, SDL_Surface * destination)
{
    SDL_Rect offset;

    //Give offsets to the rectangle
    offset.x = x;
    offset.y = y;

    SDL_BlitSurface(source, NULL, destination, &offset);
}

int main(int argc, char * args[])
{

    if ( SDL_Init(SDL_INIT_EVERYTHING) == -1 ) 
    {
        return 1;
    }
    else
    {   

      SDL_Surface * screen = SDL_SetVideoMode(SCREEN_WIDTH, 
                                   SCREEN_HEIGHT, 
                                   SCREEN_BPP,                                     
                                   SDL_SWSURFACE);

        if (screen == NULL)
        {
            return 1;

        }
        else
        {
            SDL_WM_SetCaption("Hello World", NULL);

            SDL_Surface * message = load_image("hello.bmp");
            SDL_Surface * background = load_image("background.bmp");

            apply_surface(0, 0, background, screen);
            apply_surface(320, 0, background, screen);
            apply_surface(0, 240, background, screen);
            apply_surface(320, 240, background, screen);

            if (SDL_Flip( screen ) == -1)
            {
                return 1;
            }
        }


    }

    return 0;

}

And my output:

holland@holland-litevision:~/code/cpp$ g++ main.o
main.o: In function `load_image(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
main.cpp:(.text+0x2b): undefined reference to `SDL_RWFromFile'
main.cpp:(.text+0x3b): undefined reference to `SDL_LoadBMP_RW'
main.cpp:(.text+0x4f): undefined reference to `SDL_DisplayFormat'
main.cpp:(.text+0x5d): undefined reference to `SDL_FreeSurface'
main.o: In function `apply_surface(int, int, SDL_Surface*, SDL_Surface*)':
main.cpp:(.text+0x97): undefined reference to `SDL_UpperBlit'
main.o: In function `main':
main.cpp:(.text+0xaf): undefined reference to `SDL_Init'
main.cpp:(.text+0xe7): undefined reference to `SDL_SetVideoMode'
main.cpp:(.text+0x110): undefined reference to `SDL_WM_SetCaption'
main.cpp:(.text+0x24c): undefined reference to `SDL_Flip'
collect2: ld returned 1 exit status
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:26:45+00:00Added an answer on May 25, 2026 at 1:26 am

    You’re not linking in the SDL library. Try this:

    g++ main.o `sdl-config --libs`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following piece of code, executing a pretty simple MySQL query: $netnestquery
The following code is pretty self-explanatory and my question is very simple : Why
Title pretty much sums it up. The external style sheet has the following code:
I am pretty sure the following button-activated form code should raise a Control-F12 in
Following code, when compiled and run with g++, prints '1' twice, whereas I expect
I thought this would be pretty simple, but guess not. I have the following
Pretty simple code, which I may say worked as intended in Xcode 4.1 but
I'm making a pretty simple script which takes the following parameters: -p --port integer,
I'm using Eclipse, and I have a pretty simple project, I'll save you the
I have a pretty simple scenario. I have the following HTML: <h1>Hello</h1> <input type="button"

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.