1
$\begingroup$

I have coded my own library for some purposes and use it in a ROS service. After modifying the CMakeLists file I get the following error:

undefined reference to `decirHola()' collect2: error: ld returned 1 exit status

My folders:

/catkin_ws
 /newpackage
   /src
     new_service.cpp
     /include
       json_handler.h
       json_handler.cpp

json_handler.h:

#ifndef __JSON_HANDLER_H__
#define __JSON_HANDLER_H__

#include "rapidjson/document.h"
#include "rapidjson/istreamwrapper.h"
#include "rapidjson/ostreamwrapper.h"
#include "rapidjson/writer.h"
#include "rapidjson/prettywriter.h"

#include "ros/ros.h"

using namespace std;

namespace JsonHandler {

    void decirHola(void);

}

#endif

json_handler.cpp:

#include "json_handler.h"

void DecirHola() {

    ROS_INFO("Hola Mundo");

}

in CMakeLists:

include_directories(
  ${catkin_INCLUDE_DIRS}
  src/include
)

add_library(${PROJECT_NAME}
  src/include/json_handler.cpp
)

add_executable(json_handler_lib src/include/json_handler.cpp)
target_link_libraries(json_handler_lib ${catkin_LIBRARIES})

In new_service.cpp:

#include "include/json_handler.h"

And call:

JsonHandler::decirHola();

Any solution?

Regards

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.