Jump to content
  • Advertisement
Sign in to follow this  

Including header file in multiple sources in same project

This topic is 4093 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I should know this but am drawing a complete blank. I have several files within my project that need to have access to variables in a header file. Including the header file in each of these files leads to linker errors regarding the symbols already being defined, what is the solution? Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
At the top of your headers, you can write #pragma once, to block against multiple inclusion. This will stop redefintions from including it all over the place. To access the variables

in the h file

extern var_type varname;

Then you just have to define it properly in one of your source files. It can be used anywhere that includes the header.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!