g++ gives me an error when I try to build this project and I could not menage to find out what the problem.
It's a lot code but it is a linking problem so I don't think it is necessary actually read the code and to understand it.
I have these files:
Undefined reference can also mean that you're using functions/classes that it didn't find definitions for (via header files).
In byte_dict.cpp, you use an std::vector std::vector<int> tempv;
Try adding #include <vector> at the top of byte_dict.cpp and see if the error goes away or changes.
-std=c++1
What is this?
Do you mean -std=c++11? The latest versions of g++ do not require you to say -std=c++11, they are already C++11 (C++14 currently) by default.
it's c++11, that was a typo, I'm on windows and it's not default to 11, I tried to include vector but it didn't work, even because vector is included indirectly through the byte_dict.h header.
Oh oh oh. Your problem is templates. I'm 99% sure. You can't separate the declaration of a template from the implementation like that. Yeah templates can be a *****.
An alternative to including the template implementation inside the header file itself is to use "inline" template files.
Basically, put the template implementation code inside a "my_templates_definitions.inl" file, and then #include "my_template_definitions.inl" inside bit_utils.h, after you list the template function declarations.
I would say the the include guards are working the way they should. Where by a ".cpp" file, by your OP "bit_utils.cpp" was compiled fist, causing the include guard to define "BIT_UTILS". Then when you compile the file that does need the "#include <vector>" it is not put in that ".cpp" because of the include guard.
I would suggest that you take the include files like "vector" out of the ".h" file where they do not belong and put them in the ".cpp" files that need those header files where they do belong.
The other option would be to try a different order when you compile the files and see if that helps.
If you put header files like "iostream" and "vector" in more than one ".cpp" file that is OK because they will only be included once at compile time.
Ganado is right.
Really thank you, this thing with template is pretty nasty, I didn't know it.
I resolved instantiating the template function in the cpp with the types I need.
Andy I don't think it works that way, every file is compiled separately, so the define flag are raised separately and correctly for every file so that everything is included. Then the object file are linked.