0

I just started with C++, trying to learn some basics. Right now compiling using gcc version 5.2.1 in Eclipse, project is compiled with c++11 parameter.

Now the include problem occurs when I try to #include <map> (it doesn't really matter where as long as compiler gets into it, I don't even use map yet, just trying to include it). As far as I can understand there's a problem with map itself, but it doesn't seem right. Short failure snippet here.

08:54:59 **** Incremental Build of configuration Debug for project RpnCalculator ****
make all 
Building file: ../Test/AddShouldBeRegistered.cpp
Invoking: Cross G++ Compiler
g++ -I/home/yoger/Coding/cpputest/include -O0 -g3 -Wall -c -fmessage-    length=0 -std=c++11 -v -MMD -MP -MF"Test/AddShouldBeRegistered.d" -MT"Test/AddShouldBeRegistered.d" -o "Test/AddShouldBeRegistered.o" "../Test/AddShouldBeRegistered.cpp"
Using built-in specs.
COLLECT_GCC=g++
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.2.1-22ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2) 
COLLECT_GCC_OPTIONS='-I' '/home/yoger/Coding/cpputest/include' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-std=c++11' '-v' '-MMD' '-MP' '-MF' 'Test/AddShouldBeRegistered.d' '-MT' 'Test/AddShouldBeRegistered.d' '-o' 'Test/AddShouldBeRegistered.o' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/5/cc1plus -quiet -v -I /home/yoger/Coding/cpputest/include -imultiarch x86_64-linux-gnu -MMD Test/AddShouldBeRegistered.d -MF Test/AddShouldBeRegistered.d -MP -MT Test/AddShouldBeRegistered.d -dD -D_GNU_SOURCE ../Test/AddShouldBeRegistered.cpp -quiet -dumpbase AddShouldBeRegistered.cpp -mtune=generic -march=x86-64 -auxbase-strip Test/AddShouldBeRegistered.o -g3 -O0 -Wall -std=c++11 -version -fmessage-length=0 -fstack-protector-strong -Wformat-security -o /tmp/cc8xNfBA.s
GNU C++11 (Ubuntu 5.2.1-22ubuntu2) version 5.2.1 20151010 (x86_64-linux-gnu)
compiled by GNU C version 5.2.1 20151010, GMP version 6.0.0, MPFR version 3.1.3, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/5"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/5/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/yoger/Coding/cpputest/include
 /usr/include/c++/5
 /usr/include/x86_64-linux-gnu/c++/5
 /usr/include/c++/5/backward
 /usr/lib/gcc/x86_64-linux-gnu/5/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C++11 (Ubuntu 5.2.1-22ubuntu2) version 5.2.1 20151010 (x86_64-linux-gnu)
compiled by GNU C version 5.2.1 20151010, GMP version 6.0.0, MPFR version 3.1.3, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 5ed623d6fe11f4bcc1afee70f77e33b0
In file included from /usr/include/c++/5/map:60:0,
             from ../Test/../MathOperations/MathOperationFactory.h:11,
             from ../Test/ShouldBeRegistered.h:13,
             from ../Test/AddShouldBeRegistered.cpp:9:
/usr/include/c++/5/bits/stl_tree.h: In member function ‘void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_construct_node(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type, _Args&& ...)’:
/usr/include/c++/5/bits/stl_tree.h:528:14: error: ‘__node’ does not name a type
    ::new(__node) _Rb_tree_node<_Val>;
          ^
Test/subdir.mk:66: recipe for target 'Test/AddShouldBeRegistered.o' failed
make: *** [Test/AddShouldBeRegistered.o] Error 1

08:54:59 Build Finished (took 361ms)

Alright, the file where I include map

#ifndef MATHOPERATIONFACTORY_H_
#define MATHOPERATIONFACTORY_H_

#include <map>
#include <string>

class MathOperation;

class MathOperationFactory {
public:
    MathOperationFactory();
    virtual ~MathOperationFactory();
    virtual MathOperation& findOperationNamed(const std::string &name);
private:
    typedef std::map<std::string, MathOperation*> OperationMap;
    typedef OperationMap::iterator iterator;
    OperationMap _operationsByName;
};

#endif
Claudio
  • 10,614
  • 4
  • 31
  • 71
yoger
  • 282
  • 3
  • 15
  • 3
    Show the code you are compiling. – Simple Mar 24 '16 at 08:17
  • 4
    "t doesn't really matter where " - I beg to differ. – WhozCraig Mar 24 '16 at 08:17
  • 2
    What happens if you do not use `MathOperation*` as templater parameter for the `map`. Try to create a simple map containing two `int`s for example. – Mailerdaimon Mar 24 '16 at 08:23
  • 3
    You likely have messed up with your Eclipse configuration (e.g., `Cross G++ Compiler`). Check the configuration. – Claudio Mar 24 '16 at 08:23
  • to check if there is name collision, try to put your code in a namespace. – norisknofun Mar 24 '16 at 08:25
  • 2
    "the file where I include ``" - and the file that includes *that* (ShouldBeRegistered.h) ? – WhozCraig Mar 24 '16 at 08:25
  • "I don't even use map yet"? What about `OperationMap _operationsByName`? (I believe the ultimate cause is located somewhere between lines 1 and 8 of "AddShouldBeRegistered.cpp", or somewhere between line 1 and 12 of "ShouldBeRegistered.h", or in one of the files included in those places.) – molbdnilo Mar 24 '16 at 08:45
  • @Mailerdaimon doesn't matter, error keeps popping even without entire `private` section (only place that touches map) @Claudio only things changed in configuration is including test framework (cpputest) and appending -c++11 parameter. But I think configuration might be good place to fix it up. Tried map on different project, same error. – yoger Mar 24 '16 at 08:46
  • Then, provide a small self-contained compilable example as code. as long as you don't show all of your code you are just going to be getting guesses as to what the error can be. If `#include int main(){return 0;}` also gives an error, that would be easier for everyone to troubleshoot. – default Mar 24 '16 at 08:49
  • Your compilation line is rather large... Did you try *outside of eclipse* to simply compile the file `AddShouldBeRegistered.cpp`? And does it gives same error? – Serge Ballesta Mar 24 '16 at 08:50
  • @Default that lead me to the solution, created new project, copied files, all won, just without the extra knowledge of the reason – yoger Mar 24 '16 at 09:33

3 Answers3

6

It's a problem related with memory leak detection feature of Cpputest. You can apply one of the solutions described in documentation page of Cpputest.

http://cpputest.github.io/manual.html#memory_leak_detection

Levent Esen
  • 559
  • 7
  • 18
1

I am able to avoid this issue by making sure that <map> is included before any CppUTest related includes.

example:

class1.h:

#include <map>
.
.
//your code for class 1 business logic

class1_test.cpp:

#include "class1.h"
//other include
#include <CppUTest/TestHarness.h> // at very end

Follow this rule in places wherever you are going to include CppUtest header

0

So I didn't find exact answer but managed to completely fix the issue by simply moving all project files to new project. That means that problem was somehow related to project settings, I compared compiler settings for both projects, they were the same so the reason is still covered with very fine layer of diamond hard mist.

yoger
  • 282
  • 3
  • 15