Hello, everybody. Because of many reasons, I decided to use Code:Blocks. Its version is 10.05 (includes mingw) and my OS is Windows XP SP3
And I got a problem when trying to compile a program using self-defined libraries.
I have 3 files: main.cpp, mylib.cpp and mylib.h. (Of course, they are stored in same directories (or folder)).
Each of them has content as the following:
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13
// main.cpp
#include <iostream>
#include <string>
#include "mylib.h"
usingnamespace std;
int main ()
{
string myName = "My Name";
printName (myName);
return 0;
}
You need to link the mylib translation unit.
Code::Blocks will automatically do that when you add mylib.cpp to your project (Project/Add files).
When creating new files, it's best to do it using Code::Blocks via File/New - it will then ask you whether to add the file to your current project.
And you should never use "using namespace" in header files. It injects the entire std namespace into any translation unit that directly or indirectly includes this header file, whether the user wants it or not.