views:

44

answers:

1

I'm having a project which compiles perfectly with gcc, but fails to compile under Greenhills Integrity environment.

The problem boils down to this three files:

MyVector.cpp // contains function testVector
MyVector.hpp // contains template vector<>
SomeFile.cpp

MyVector.hpp contains template-class for a vector, and MyVector.cpp contains a testing function unrelated to MyVector.hpp's templates.

Now, when I'm using MyVector.hpp's vector templates in SomeFile.cpp, somehow, the function testVector gets injected into SomeFile.cpp. When I cease to use vector in SomeFile.cpp (I'm still #include'ing it of course, I'm just not instantiate the template there) it works perfectly.

Moreover when I injected a warning into function testVector, the compiler showed the warning when I compiled SomeFile.cpp!

Moreover, the build system recompiles SomeFile.cpp when I'm changing things in MyVector.cpp.

When I'm deleting the testVector function from MyVector.cpp and move it to a new NewFile.cpp - it compiles.

No, I didn't include the cpp file by mistake, honest, I double checked it, and greped all my source code.

I have no idea what's going on. I'll be glad for any clue.

A: 

How are you implementing vector? I'm thinking you're implementing this in MyVector.cpp and including MyVector.cpp at the end of MyVector.hpp. If this is the case, including MyVector.hpp in SomeFile.cpp will trigger a rebuild of SomeFile.cpp when you change MyVector.cpp. I'd suggest run it through the pre-processor and see where the testVector() is being included from.

Tareq A. Siraj
-1. I'm quoting myself "No, I didn't include the `cpp` file by mistake, honest... I double checked it." It is implemented as a regular template in the `h` file only. In the `MyVector.cpp` file there's only a single 'testVector` function, that's it. Please read the question more carefully. I added a paragraph exactly to prevent such simplistic answer. Also please note the code compiles with `g++`.
Elazar Leibovich
Have you tried the pre-processor like I suggested?
Tareq A. Siraj