Author Topic: Small Bug  (Read 4419 times)

Offline Swiftslide

  • Single posting newcomer
  • *
  • Posts: 4
Small Bug
« 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.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Small Bug
« Reply #1 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Swiftslide

  • Single posting newcomer
  • *
  • Posts: 4
Re: Small Bug
« Reply #2 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.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Small Bug
« Reply #3 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Small Bug
« Reply #4 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.