我正在尝试在我的 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 编译器与称为 catkin 的ROS构建系统结合使用。
所以有一些奇怪的事情:
看起来它已正确链接,因为如果我从 target_link_libraries 中删除
cpp_redis
andtacopie
,我会得到更多未定义的引用,而我的 IDE 只会识别所有内容。方法的参数似乎有问题,因为如果我在
client
没有任何参数的情况下调用方法,client.commit()
那么它只会编译并运行。我用于 redis 库的代码是从他们提供的示例中获得的,因此我认为它们是正确的。
我真的不知道出了什么问题,如果我尝试在没有catkin
. 我希望你们能帮助我。谢谢!