Sign in to follow this  
zeeli

C++ Linking Problem

Recommended Posts

zeeli    239
Hey, I've ran into a problem.. yea So. I have a file input.cpp that includes render.h render.h contains variables x, y ,z that i need in input.cpp for moving in my scene. in render.cpp(and many other files) I also include render.h And as you guessed it generates lots and lots of "already defined" -errors. You ask me why do you put those variables in *.h file? Because if I put them in *.cpp file, i cant use x, y, z variables in my other *.cpp files. I hope you understood my problem. So is there somekind of a compromise?

Share this post


Link to post
Share on other sites
jpetrie    13103
This article discusses issues you should learn about.

Although the need for globals like that represents a serious design flaw, the immediate band-aid solution is the "extern" keyword. Read the linked article and you will understand why you get those errors and, hopefully, correct some misconceptions you might have about C++'s compilation model and the way the preprocessor handles #include directives.

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