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 8156181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:52:17+00:00 2026-06-06T16:52:17+00:00

I’m using the code here and I want all the functions which call SDL

  • 0

I’m using the code here and I want all the functions which call SDL functions to be in a different header file instead of the main .cpp file. So I created a new file called Methods.h.
Here is what the files look like:

main.cpp:

#include "Methods.h"
...

Methods.h:

#include "SDL/SDL.h"
#include "SDL/SDL_opengl.h"
....

And I removed all the functions from main and put them in Methods.h

When I try to build the project, it says “multiple definition error”.

/media/Data1/Projects/OpenGL/Game2/Methods.h|29|multiple definition of `event'|
obj/Debug/main.o:/media/Data1/Projects/OpenGL/Game2/Methods.h|29|first defined here|
obj/Debug/src/Machine.o||In function `drawFrame()':|
/media/Data1/Projects/OpenGL/Game2/Methods.h|29|multiple definition of `drawFrame()'|
obj/Debug/main.o:/media/Data1/Projects/OpenGL/Game2/Methods.h|29|first defined here|
obj/Debug/src/Machine.o||In function `init_GL()':|
/media/Data1/Projects/OpenGL/Game2/Methods.h|73|multiple definition of `init_GL()'|
obj/Debug/main.o:/media/Data1/Projects/OpenGL/Game2/Methods.h|73|first defined here|
obj/Debug/src/Machine.o||In function `init()':|
/media/Data1/Projects/OpenGL/Game2/Methods.h|97|multiple definition of `init()'|
obj/Debug/main.o:/media/Data1/Projects/OpenGL/Game2/Methods.h|97|first defined here|
obj/Debug/src/Machine.o||In function `clean_up()':|
/media/Data1/Projects/OpenGL/Game2/Methods.h|123|multiple definition of `clean_up()'|
obj/Debug/main.o:/media/Data1/Projects/OpenGL/Game2/Methods.h|123|first defined here|
  • 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-06-06T16:52:19+00:00Added an answer on June 6, 2026 at 4:52 pm

    It looks like you have some function definitions in your header file, this means that you’ll get a separate definition of each function from each source file that includes the header. They need to be declared inline in order to allow them to be defined in every translation unit that includes the header:

    // Methods.h
    #ifndef METHODS_H
    #define METHODS_H
    
    inline void initGL() {
        // do stuff
    }
    
    #endif
    

    Alternatively, you could just declare them in the header, and move the definitions to a source file:

    // Methods.h
    #ifndef METHODS_H
    #define METHODS_H
    
    void initGL();
    
    #endif
    
    // Methods.cpp
    #include "Methods.h"
    
    void initGL() {
        // do stuff
    }
    

    There’s also a global variable. If you want to keep that, you’ll have to move the definition into a source file, and declare it extern in the header file. Alternatively, you could replace it with a function that accesses a static variable:

    inline SDL_Event & event() {
        static SDL_Event instance;
        return instance;
    }
    

    This has the advantage, and the disadvantage, that it’s initialised the first time the function is called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
i want to parse a xhtml file and display in UITableView. what is the
I am using parse_ini_file to read the contents of a file however it is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.