Catkin / ROS C ++库链接错误(未定义引用)

时间:2017-06-07 14:03:41

标签: c++ redis cmake ros catkin

我正在尝试在我的ROS项目中使用CPP Redis库。它似乎无法正确链接到cpp-redis,在以下代码中:

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "communication.h"
#include "ros/ros.h"

int main (int argc, char **argv)
{
    // Initialize and get a handle
    ros::init(argc, argv, "team3");
    ros::NodeHandle n;

    //directly from the example
    cpp_redis::redis_client client;
    client.connect("127.0.0.1", 6379, [](cpp_redis::redis_client&) {
        std::cout << "client disconnected (disconnection handler)" << std::endl;
    });

}

出现以下错误:

/home/wouter/Documents/Team3_Visitor_Goal/ros/src/team3/src/publisher.cpp:17: undefined reference to `cpp_redis::redis_client::connect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, std::function<void (cpp_redis::redis_client&)> const&)'

我的CMakeLists.txt看起来如下:

cmake_minimum_required(VERSION 2.8.3)
project(team3)

set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_C_COMPILER "clang")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 11) #set correct version

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  naoqi_driver
  roscpp
  std_msgs
)

## Declare a catkin package
catkin_package()

## Build talker and listener
include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(pepper src/publisher.cpp)
target_link_libraries(pepper ${catkin_LIBRARIES} cpp_redis tacopie)

我将CLang编译器与ROS的构建系统结合使用,称为catkin。

所以有一些奇怪的事情:

  • 看起来它是正确链接的,因为如果我从target_link_libraries中删除cpp_redistacopie,我会得到更多未定义的引用,而我的IDE只能识别所有内容。

  • 似乎方法的参数有问题,因为如果我在client上调用一个没有任何参数的方法,例如client.commit(),那么它只是编译并运行。我用于redis库的代码是我从他们提供的示例中得到的,所以我认为它们是正确的。

我真的不知道出了什么问题,如果我尝试在没有catkin的项目中使用它,它会正常工作。我希望你们能帮助我。谢谢!

0 个答案:

没有答案