Sign in to follow this  

cyclical dependency (?) [solved]

This topic is 3860 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'm having some compiling problems due to what I 'think' is a cyclical dependency issue. I'm writing some simple straight C code, in a header file called winmain.h I have defined some globals that are used by winmain.cpp (this file obviously includes winmain.h) and wndproc.cpp (again this file includes winmain.h), it's a LNK2005 error thats telling me the objects have already been defined in winmain.obj - how can I rectify this?

Share this post


Link to post
Share on other sites
I'm not quite sure how you clear up some cyclical issues in C (I would assume it's similar to that of C++?)

Could I see some code? Perhaps I could help..

Share this post


Link to post
Share on other sites
It's not a cyclical definition problem. You need to declare your global variables as extern in all translation units except one, and define them in the remaining translation unit only. Your error indicates that you have defined them in all translation units.

Share this post


Link to post
Share on other sites
Quote:

It's not a cyclical definition problem. You need to declare your global variables as extern in all translation units except one, and define them in the remaining translation unit only. Your error indicates that you have defined them in all translation units.


Thanks for that! It works fine now.

Share this post


Link to post
Share on other sites

This topic is 3860 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.

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