I’m trying to bring life into an old “object-oriented, C++ to openScad university project, that has been asleep since 2013. It was meant to give us a program to write C++ code and get it translated to .scad code ready for further refinement. I have downloaded code from git and installed with C++14 on Eclipse IDE on my Linux Mint computer. There is no tutorial to find, there are few remnants to be found on internet. So you are left on your own. When I try to compile after having put all necessary .h and .ccp files in the project , I get a lot of errors like the first one below. I hope that, if I could get help to solve this first error or at least be helped into the right direction, I could manage the rest myself, because they seem to how the same “malaise”.
In the console output I read this:
...In function `Component::moveToLink(Component const&, int)':
…/Debug/../Component.cpp:24: undefined reference in function `Component::moveToLink(Component const&, int)':
In Component.cpp we find:
Component & Component::moveToLink(const Component & base, int link_id)
{
RefSys link = base.getLink(link_id);
TransformMatrix trans = link.getTransformMatrix();
double xa, ya, za;
trans.getGlobalXYZAngles(xa,ya,za);//error:undefined reference to `TransformMatrix::getGlobalXYZAngles(double&, double&, double&) const'
double x,y,z;
trans.getGlobalTranslation(x,y,z);//error:undefined reference to `TransformMatrix::getGlobalTranslation(double&, double&, double&) const'
//rotate and translate
this->rotate(xa,ya,za);
this->translate(x, y, z);
return * this;
}
I understand the error message: “undefined reference to `TransformMatrix::getGlobalXYZAngles(double&, double&, double&) const'”
as it says, that there is no defined reference to the getGlobalXYZAngles() function. But in the start of Component.cpp file I have these includes:
...and here it comes:
/**
* Gets the rotation angles about the fixed axes x,y,z.
* Obtains the rotation angles about the fixed x,y,z
* (Roll,Pich,Yaw).
* \param x rotation (in degrees) around initial fixed x
* \param y rotation (in degrees) around initial fixed y
* \param z rotation (in degrees) around initial fixed z
*/
void getGlobalXYZAngles(double &x, double &y, double &z) const;
. . . and goes on with:
void getGlobalTranslation(double &x, double &y, double &z) const;
void translate(double x, double y, double z);
void relTranslate(double x, double y, double z);
/**
* check if matrix equals identity
* return true when matrix is identitiy
*/
bool inline isIdentity(){
bool id = true;
for (int i=1;i<=4;i++){
for(int j=1; j<=4;j++){
if (i==j)
id = id && (get(i,j)==1);
else
id = id && (get(i,j)==0);
if(!id){
return false;
}
}
}
return id;
}
};
For the completeness I also add TransformMatrix.cpp
TransformMatrix& TransformMatrix::operator *(TransformMatrix const & matrix){
TransformMatrix* result = new TransformMatrix();
for (int i=1;i<=4;i++){
for (int j=1;j<=4;j++){
double value = 0;
for (int k=1;k<=4;k++){
value+=get(i,k)*matrix.get(k,j);
}
result->set(i,j,value);
}
}
}
In the Hope this is helps, I sign
Bo Nystedt
Thank you so much for your answer:
It is built like this:
Building target: 031319_1045_Error_Chasing
Invoking: GCC C++ Linker
g++ -o "031319_1045_Error_Chasing" ./AbstractObject.o ./ColorDecorator.o ./Component.o ./CompositeObject.o ./CylinderObject.o ./DXFLinearExtrude.o ./Imported.o ./IndentWriter.o ./Matrix.o ./MirrorDecorator.o ./ObjectDecorator.o ./Point3D.o ./RefSys.o ./RotMatrix.o ./ScaleDecorator.o ./TransformDecorator.o ./TransformMatrix.o ./globalfunctions.o ./main.o -lglut -lrt -lGL -lGLU -lGLEW -lm -lXrandr -lXi -lX11 -lXxf86vm -ldl -lXinerama -lXcursor -ldl
./TransformMatrix.o: In function `__gnu_cxx::new_allocator<double>::new_allocator()':
but I also now see this: 031319_1045_Error_Chasing/Debug/../TransformMatrix.cpp:10: multiple definition of `TransformMatrix::getInv() const'. Perhaps that's the start of the problem. I'll go for that.I'll report what happens.
Bo
Undefined reference means the linker cannot find the object file containing the implementation.
"undefined reference" can be either a compile time or link time error. The error message the OP posted is clearly a compile time error.
...In function `Component::moveToLink(Component const&, int)':
…/Debug/../Component.cpp:24: undefined reference in function `Component::moveToLink(Component const&, int)':
@OP: The declarations in transformmatrix.h certainly look like they should satisfy the compiler when compiling components.cpp. I'm at a loss to explain the error. Some of the things I would look for:
- Conflicting header files with the same name in the search path (both compiler and local).
- Namespace issues.
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
There something more I I don't understand. I can't see any multiple definitions:
/home/bo/workspace19/031319_1045_Error_Chasing/Debug/../TransformMatrix.cpp:10: multiple definition of `TransformMatrix::getInv() const'
./Component.o:/home/bo/workspace19/031319_1045_Error_Chasing/Debug/../TransformMatrix.cpp:10: first defined here
./TransformMatrix.o: In function `TransformMatrix::operator*(TransformMatrix const&)':
makefile:44: recipe for target '031319_1045_Error_Chasing' failed
/home/bo/workspace19/031319_1045_Error_Chasing/Debug/../TransformMatrix.cpp:37: multiple definition of `TransformMatrix::operator*(TransformMatrix const&)'
./Component.o:/home/bo/workspace19/031319_1045_Error_Chasing/Debug/../TransformMatrix.cpp:37: first defined here
./Component.o: In function `Component::moveToLink(Component const&, int)':
/home/bo/workspace19/031319_1045_Error_Chasing/Debug/../Component.cpp:23: undefined reference to `TransformMatrix::getGlobalXYZAngles(double&, double&, double&) const'
One thing I have found helpful in situations like this is to enable a full compiler listing.
Although tedious, by reviewing the compiler listing you can see exactly what the compiler sees.
A couple of things to look for:
1) Each time the compiler processes an include file, it lists the full path name of the include file. Make sure the include files are coming from where you think they're coming from. Make sure the contents agree with what you think they should include.
2) Make sure the includes are not within range of some #ifdef that causes the #include to be excluded.
You have been asked to use code tags. PLEASE DO SO. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
If you're not going to make the slightest bit of effort to make your posts readable, why should we spend the slightest bit of effort helping you?