Jump to content
  • Advertisement


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


Can't compile in release mode

This topic is 5888 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 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 this post

Link to post
Share on other sites
In your header:

#ifndef _MISC_H
#define _MISC_H



*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 this post

Link to post
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 this post

Link to post
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.h
inline 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 this post

Link to post
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!

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!