Sign in to follow this  
edd1986

Including header file in multiple sources in same project

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this