Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: Swiftslide on August 22, 2010, 04:24:19 am

Title: Small Bug
Post by: Swiftslide on August 22, 2010, 04:24:19 am
When creating a class, Code Blocks writes in the .cpp file an #include statement for the associated .h file. However, by default these files are placed in separate folders (.h files in ~/include and .cpp in ~/src). The #include statement fails to reflect this, and hence the program will not compile without alteration.\
Not a huge deal, of course; but if you're going to auto-generate such statements, it make sense for them to be correct.
Title: Re: Small Bug
Post by: MortenMacFly on August 22, 2010, 01:40:04 pm
When creating a class, Code Blocks writes in the .cpp file an #include statement for the associated .h file.
This is not a bug, all you need to do is to setup your project accordingly. If you place you header files in a different folder, you'll need to tell the compiler the include path. This is the same on the command line and every other IDE. So it is most common and surely not a bug. BTW: In C::B you can even use scripting to automise this.
Title: Re: Small Bug
Post by: Swiftslide on August 23, 2010, 02:09:34 am
I'd say it's a bug, considering it's Code Blocks that is putting the.h and .cpp files into separate folders (by default) but not updating the #include statement to reflect this.
Title: Re: Small Bug
Post by: MortenMacFly on August 23, 2010, 06:54:21 am
I'd say it's a bug, considering it's Code Blocks that is putting the.h and .cpp files into separate folders (by default) but not updating the #include statement to reflect this.
No! It's definitely not a bug. If you place header files into different folders in 99.9% of the cases you don't change the include statement, but the include path you pass to the compiler. Everything else makes no sense at all, except you are developing an SDK core or alike. But even then it's really seldom. Have a look at boost for example.

So. Read yourself into scripting and write yourself a 3-liner that iterates through your projects and sets the compiler's include path and you're done.
Title: Re: Small Bug
Post by: Jenna on August 23, 2010, 07:53:58 am
If you use the class-wizard ("File -> New -> class") just check "Header and implementation file shall be in the same folder".
The default folder is the actual projects root folder, and the setting is remembered, so you do not need to change it everytime.

A possible solution could be to a check whether the headers folder is already in compilers search dirs and if not ask whether it should be added.