bring life into an old “object-oriented, C++ to openScad university projec

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:

#include "Component.h"
#include "globalfunctions.h"
#include "RefSys.h"
#include "Translation.h"
#include "TransformMatrix.h"
#include "RotMatrix.h"
#include "Union.h"

So, what I can see there are a TransformMatrix.h file included as well as a TransformMatrix.cpp included. What more should there be?

TransformMatrix. h looks like this:
#pragma once
#include <math.h>
#include "Matrix.h"
#include <utility>

class TransformMatrix: public Matrix<double,4,4>
{
public:

TransformMatrix() :
Matrix<double,4,4>()
{
for (int i=1;i<=4;i++){
set(i,i,1);
}
}
void printMatrix() const{
for (int i=1 ; i<=4 ; i++){
std::cout << "| ";
for (int j=1; j<=4; j++){

std::cout << get(i,j) << " ";
}
std::cout << "|" << std::endl;
}
}
TransformMatrix & operator*(TransformMatrix const& matrix);

TransformMatrix getInv() const;

void transform(TransformMatrix tr);
void relTransform(TransformMatrix tr);
void rotateEulerZXZ(double z,double xp, double zpp);
void rotateEulerZYZ(double z,double yp, double zpp);
void rotate(double x, double y, double z);
void relRotateEulerZXZ(double z,double xp, double zpp);
void relRotateEulerZYZ(double z,double yp, double zpp);
void relRotate(double x, double y, double z);
void rotateX(double x);
void rotateY(double y);
void rotateZ(double z);
void relRotateX(double x);
void relRotateY(double y);
void relRotateZ(double z);

...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

#include "TransformMatrix.h"
#include "Math.h"

TransformMatrix TransformMatrix::getInv() const {
TransformMatrix inv;

//Traspose the 3x3 submatrix
for (int i=1;i<=3;i++){
for (int j=1;j<=3;j++){
inv.set(i,j,get(j,i));
}
}

//Las row all 0 but last
for (int i=1;i<=3;i++)
inv.set(4,i,0);
inv.set(4,4,1);

double e14 = get(1,4)*get(1,1) + get(2,4)*get(2,1) + get(3,4)*get(3,1) ;
double e24 = get(1,4)*get(1,2) + get(2,4)*get(2,2) + get(3,4)*get(3,2) ;
double e34 = get(1,4)*get(1,3) + get(2,4)*get(2,3) + get(3,4)*get(3,3) ;

inv.set(1,4,-e14);
inv.set(2,4,-e24);
inv.set(3,4,-e34);

return inv;

}

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
Last edited on
Undefined reference means the linker cannot find the object file containing the implementation.

Somewhere there is a cpp file containing the implemention of the function TransformMatrix::getGlobalXYZAngles

That cpp file needs to be compiled into an object file.

Then the linker needs to be told to use that object file.

How are you building this code?

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
repeater wrote:
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.
this is from main.cpp(I have kept it as simple as possible, just calling for a Cylinder object .)

#include <tuple>
#include <vector>
#include <math.h>
#include <sstream>
#include <string>
#include <iostream>
#include <fstream>

#include "IndentWriter.h"
#include "ColorDecorator.h"
#include "ObjectDecorator.h"
#include "AbstractObject.h"
#include "Cylinder.h"

void render(IndentWriter &writer)
{
Component cyl(Cylinder(25,10));
}

int main(int argc, char **argv)
{
IndentWriter writer;
return 0;
}


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'
Last edited on
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?
Last edited on
Registered users can post here. Sign in or register to post.