0

I had a function to get points inside a 3D arc working inside a file but, trying to order the code into the appropriate folders, I broke it, and I don't know why because I think I am including it correctly.

Originally a lot of calculations were inside a file "messages.cpp", but it is supposed to have just the messages and the calculations should be in Calculations folder.

So now messages.cpp is something like this:

#include "../../FGProcessorModule/Calculations/ArcToPoints.h"
namespace myNamespace {
void MsgProvider::onEvent{
std::vector<Formulas::LLPoint> allPoints = ArcToPoints(center, start, end);
}
}

In "../../FGProcessorModule/Calculations/ArcToPoints.h" I have:

#ifndef ARCTOPOINTS_H
#define ARCTOPOINTS_H

#include blablabla

namespace myNamespace{

std::vector<Formulas::LLPoint> ArcToPoints (Formulas::LLPoint, Formulas::LLPoint, Formulas::LLPoint);

}

#endif /* ARCTOPOINTS_H */

And finally in "../../FGProcessorModule/Calculations/ArcToPoints.cpp" I have:

#include "ArcToPoints.h"
namespace myNamespace{
std::vector<Formulas::LLPoint> ArcToPoints (Formulas::LLPoint center, Formulas::LLPoint start, Formulas::LLPoint end){
        //Lots of calculations
}
}

I think everything is OK but I receive this error when I want to compile:

undefined reference to `FVIS::ArcToPoints(Formulas::LLPoint, Formulas::LLPoint, Formulas::LLPoint)'

Daniel Viaño
  • 485
  • 1
  • 9
  • 26
  • I think in your file `ArcToPoints.cpp` you should also put the whole path into the `#include` statement, because the paths are relative to where the compiler is started. Or what you could do is add the path to the include paths. (E.g. with the `-I` argument for gcc) – David Wright Oct 31 '17 at 09:59
  • Same problem doing that, but thank you for the suggestion. – Daniel Viaño Oct 31 '17 at 10:02
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – user7860670 Oct 31 '17 at 10:02
  • 3
    "undefined reference" does not come from the compiler, but from the linker. Perhaps you missed adding the new file to the build? – Bo Persson Oct 31 '17 at 10:02
  • No, I created them in Eclipse and they are in the project. – Daniel Viaño Oct 31 '17 at 10:09
  • Oh of course @BoPersson! @Daniel Viaño maybe Eclipse did not regenerate the makefiles in the background. Sometimes all it takes is a refresh, clean and rebuilding the index. – David Wright Oct 31 '17 at 10:12
  • Unfortunately that didn't solve the problem, same error. – Daniel Viaño Oct 31 '17 at 10:32

1 Answers1

0

I don't know if this will help others as it is a very specific problem, this is a project using ros and catkin.

I was missing including the new created file in CMakeLists.txt. Now it compiled just fine.

Daniel Viaño
  • 485
  • 1
  • 9
  • 26