In headers ( .h ) you have the declarations (and the implementations for inline functions or templates).
In source files (.cpp) you have the definitions.
When you use #include "some header.h" that line is replaced by the contents of the file "some header.h"
When compiling a program you are compiling (and linking) source files, headers don't get compiled
If your frequently used functions are inlined you can just use your own header, if they aren't you should create both a header and a source file then you can decide whether to build a static or dynamic library or compile and link your cpp file each time
Originally I was working in komodo and compiling on the command line with g++ ... I had a shell script that had the g++ command with all the "-I, -L" etc in it.
Then as the project grew, I decided to pull it all into codeblocks, which i am using for the first time.
This obviously made me have to think about organizing the code, thus my original questoin.
But codeblocks .. something about how its compiling, is generating errors that the command line didnt.
Stuff like this, in my included .cpp file:
1 2
inline std::string TrimStr(const std::string& Src, const std::string& c = " \r\n"){
//includes.cpp|1|error: ‘string’ in namespace ‘std’ does not name a type
and
1 2 3 4
vector<string> explode( const string &delimiter, const string &str){
//includes.cpp|10|error: expected constructor, destructor, or type conversion before ‘<’ token|
So its kinda driving me nuts. Also it found a few "warnings" that the command line didnt.
This has been a great (and frustrating) learning experience however!
You are missing <vector>
You shouldn't #include cpp files (they should be compile and linked)
codeblocks compiles all cpp files unless you explicitly tell it not to do that:
right click on the file you don't want to compile > Properties... > Build > select the options you want
Ahh yeah I saw the <vector> as soon as I posted that.
So, one question about what you said:
So right now, by default, codeblocks is compiling and linking the file. This is why it isnt working?
If I remove the includes.cpp .. how will it know to compile and link it, or will it just do it because its part of the project?
You indicated that best practice would be to compile and link, rather than include, so I'd rather do it right.
So .. if I remove the include references to includes.cpp -- would I then have to make includes.cpp have its own main() , and its own #include for any functionality it needs?
You can have only one call of main() as it is the entry point for your program.
You should #include all headers needed by includes.cpp.
To use symbols defined in includes.cpp from other files you should put the declarations on a header file ( includes.h ? ) and #include it in all cpp files using those symbols
As I said before, for default codeblocks compiles cpp files which are in the project