Linking namespace to executable
Hello,
i have two executable i build them with:
add_executable(MapProcessing src/MapProcessing.cpp BasicCalculation.cpp)
added minimal example
function header MapProcessing.h
#ifndef MAPPROCESSING_H_
#define MAPPROCESSING_H_
#include <BasicCalculation.h>
class MapProcessing
{
public:
MapProcessing();
private:
void DoSomething();
};
#endif /* MAPPROCESSING_H_ */
function cpp
#include "map_processing.h"
void MapProcessing::DoSomething(){
Eigen::Vector2d vector(1,0);
double test=BasicCalculation::test;
int p=BasicCalculation::a();
double test=BasicCalculation::AngleBetweenXaxisAndVector(vector);
}
}
header namespace:
#ifndef BASICCALCULATION_H_
#define BASICCALCULATION_H_
#include <Eigen/Core>
#include <Eigen/Eigenvalues>
#include <Eigen/Geometry>
namespace BasicCalculation{
double AngleBetweenXaxisAndVector(const Eigen::Vector2d& vector);
static double test=2;
static int a(){return 1;}
};
#endif /* BASICCALCULATION_H_ */
cpp namespace
#include "BasicCalculation.h"
using namespace BasicCalculation;
double AngleBetweenXaxisAndVector(const Eigen::Vector2d& vector)
{
calculate angle;
return angle;
}
when i build this. I get an error
undefined reference to `BasicCalculation::AngleBetweenXaxisAndVector(Eigen::Matrix<double, 2, 1, 0, 2, 1> const&)'
but variable test and function a() are working.
I have no idea why...
can u please help?
The function named in the undefined reference error is not linked to your executable. Error sources are: You named it slightly different (including the function signature) or you did not compile+link the code that contains this. For more help you've gotta come up with a full minimal example.
ok I edited my full minimal example
I don't see where `namespace_one` is defined? What is in `namespace.h`?
sry namespace_one is my BasicCalculation i have added the full minimal example and delete namespace_one now