ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Linking namespace to executable

asked 2013-08-14 03:46:29 -0600

Hunk gravatar image

updated 2013-08-14 04:19:31 -0600


i have two executable i build them with:

 add_executable(MapProcessing src/MapProcessing.cpp BasicCalculation.cpp)

added minimal example

function header MapProcessing.h


#include <BasicCalculation.h>

class MapProcessing
    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:


#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;}


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?

edit retag flag offensive close merge delete



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.

dornhege gravatar image dornhege  ( 2013-08-14 03:52:55 -0600 )edit

ok I edited my full minimal example

Hunk gravatar image Hunk  ( 2013-08-14 04:08:15 -0600 )edit

I don't see where `namespace_one` is defined? What is in `namespace.h`?

joq gravatar image joq  ( 2013-08-14 04:16:43 -0600 )edit

sry namespace_one is my BasicCalculation i have added the full minimal example and delete namespace_one now

Hunk gravatar image Hunk  ( 2013-08-14 04:19:06 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-08-14 04:32:11 -0600

dornhege gravatar image

The function double AngleBetweenXaxisAndVector(const Eigen::Vector2d& vector) in your cpp is not defined in the namespace. The using directive does NOT do this. It does something else.

edit flag offensive delete link more


shit i am an idiot thank you

Hunk gravatar image Hunk  ( 2013-08-14 04:37:22 -0600 )edit

Question Tools

1 follower


Asked: 2013-08-14 03:46:29 -0600

Seen: 153 times

Last updated: Aug 14 '13