Apologies if you've seen this complaint a hundred times.
- I've just installed Code::Blocks
- I installed it with MingW
- I'm using it for the first time
- I created a console app
- I added a new class called Text (with defaults)
- I hit "build"
- It threw a list of errors:
||=== Test99, Debug ===|
D:\Users\prawnhead\Documents\C++\Test99\src\Text.cpp|1|error: Text.h: No such file or directory|
D:\Users\prawnhead\Documents\C++\Test99\src\Text.cpp|3|error: 'Text' has not been declared|
D:\Users\prawnhead\Documents\C++\Test99\src\Text.cpp|3|error: ISO C++ forbids declaration of 'Text' with no type|
D:\Users\prawnhead\Documents\C++\Test99\src\Text.cpp||In function 'int Text()':|
D:\Users\prawnhead\Documents\C++\Test99\src\Text.cpp|6|warning: no return statement in function returning non-void|
D:\Users\prawnhead\Documents\C++\Test99\src\Text.cpp|8|error: expected constructor, destructor, or type conversion before '::' token|
D:\Users\prawnhead\Documents\C++\Test99\src\Text.cpp|13|error: 'String' does not name a type|
||=== Build finished: 5 errors, 1 warnings ===|
Pardon my stupidity, but how does a file that Code::Blocks just created for me not exists? Thanks for any help.
For anyone actually needing an answer ...
When a new class is added to a Code::Blocks project a message appears:
The new class has been created.
Do you want to add it to the current project?
You answer Yes. But this does not ensure the new class is included when you build the project. The default folders that you probably used \src for .cpp files and \include for .h files are not part of the search path (where the #include directive looks for files) unless you configure it in either the project or the application settings.
To add \include and \src to the search folders list for this project only:
- Right-click your project under Workspace in the Management pane
- Select Build Options ...
- Click the Search Directories tab.
- Click Add and locate either the \include or \src folder for your project
- When asked keep this as a relative path?, click Yes
- Repeat for the other folder
- Try your build again
You will likely need to alter these settings also for your Release configuration. If you want all your projects to work the same way, update Code::Block's Settings. Check these resources:
- http://www.allegro.cc/forums/thread/600860
- http://wiki.daevsgui.com/CodeBlocks:_Add_search_directory
Oh yeah, and this information is not in the manual or the FAQ. The application has no on-board help. Searching the forum or Google for this does not quickly yield an answer when you don't know what you're looking for. Oh, and the the forum is patrolled.