#### Archived

This topic is now archived and is closed to further replies.

# Can't compile in release mode

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

## Recommended Posts

I''m going nuts trying to do such a simple thing in VC++. I have almost completely written my first game in C++ (started with the game engine from the OpenGL Game Programming book), but I can''t compile it in release mode, though it compiles fine in debug mode. The reason for the build failure is a routine which I want to call from one of my source files (a bitmap loading routine). I thought that the clean, simple way would be to create a .h file ("misc.h") with the routine in it, then simply include the file in the .cpp file which calls the routine. However, when I compile I get 3 error LNK2005s telling me that the routine has already been defined. This is because the .cpp file which includes the misc.h file is itself included in other files, therefore creating multiple copies of the contents of the new .h file. How can I modify my code so that the .h file is included ONLY with the one .cpp file?

##### Share on other sites

  #ifndef _MISC_H#define _MISC_H//code#endif

*lost count of all the 500 errors trying to post this*

------------
Where''d the engine go? Where''d it go? Aaaaaah!!
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155

##### Share on other sites
Thanks for your answer LockePick, but I had already done that. I have also tried moving the code into the object which calls the routine but still get the same error. I have tried adding #include "misc.h" to alternative files, but get similar errors. I just don''t really understand the way C++ includes files.

##### Share on other sites
Did you put the entire function in the head file (misc.h) and
include it in more than one file? If it''s small, you can
inline the function:

// in misc.hinline MyBitmapLoad(...)    {    // Blah    }// end

If you don''t put the inline keyword, the compiler will
make two or more copies of that function, precisely the error
you''re getting.

If the function is large, you should put it in its own .cpp.

Kami no Itte ga ore ni zettai naru!

##### Share on other sites
Thank you, thank you, thank you Tangentz! I have been at this for literally hours, searching Google and the MSDN. I had worked out that I could possibly use the /FORCE option in the linker, though I was having difficulty working out where to actually set this. Never mind though, coz your suggestion worked. Cheers!