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

Linking namespace to executable

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

Hunk gravatar image

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

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?

edit retag flag offensive close merge delete

Comments

1

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 -0500 )edit

ok I edited my full minimal example

Hunk gravatar image Hunk  ( 2013-08-14 04:08:15 -0500 )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 -0500 )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 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

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

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

Comments

shit i am an idiot thank you

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

Question Tools

1 follower

Stats

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

Seen: 171 times

Last updated: Aug 14 '13