google相关的基础软件
1、glog
GlogTest.cpp

#include <iostream> #include <stdlib.h> #include <glog/logging.h> #include <ros/ros.h> int main(int argc, char** argv) { google::InitGoogleLogging(argv[0]); google::SetLogDestination(google::GLOG_INFO, "./test_glog_info"); ros::init(argc, argv, "glog_node"); ros::NodeHandle nh("glog"); LOG(INFO) << "Hello glog"; return 0; }
CMakeLists.txt

add_executable(glog_test src/Test/GlogTest.cpp)
target_link_libraries( glog_test
${catkin_LIBRARIES}
glog
)
不需要添加find_package和include_directories
2、gflags
GflagsTest.cpp

// // Created by gary on 2021/1/16. // #include <iostream> #include <gflags/gflags.h> #include <ros/ros.h> DEFINE_string(host, "127.0.0.1", "the sever host"); DEFINE_int32(port, 12306, "the sever port"); int main(int argc, char ** argv) { google::SetUsageMessage("\n usage\n"); google::ParseCommandLineFlags(&argc, &argv, true); ros::init(argc, argv, "gflags_node"); ros::NodeHandle nh("gflags"); std::cout << "The sever host is: " << FLAGS_host << ", the server port is: " << FLAGS_port << std::endl; return 0; }
CMakeLists.txt

add_compile_options(-std=c++11) add_compile_options(-pthread) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread") find_package(gflags REQUIRED) include_directories(${gflags_INCLUDE_DIRS}) add_executable(gflag_test src/Test/GflagsTest.cpp) target_link_libraries( gflag_test ${catkin_LIBRARIES} gflags )
3、Abseil
Abseil.cpp

#include <iostream> #include <string> #include <vector> #include "absl/strings/str_join.h" #include <ros/ros.h> int main(int argc, char** argv) { ros::init(argc, argv, "gtest_node"); ros::NodeHandle nh("gtest"); std::vector<std::string> v = {"foo","bar","baz"}; std::string s = absl::StrJoin(v, "-"); std::cout << "Joined string: " << s << "\n"; return 0; }
CMakeLists.txt

find_package(absl REQUIRED) add_executable(abseil_test src/Test/Abseil.cpp) target_link_libraries( abseil_test ${catkin_LIBRARIES} absl::strings )
4、Gtest
外层
GTestMain.cpp

#include <iostream> #include <ros/ros.h> int main(int argc, char** argv) { ros::init(argc, argv, "gtest_node"); ros::NodeHandle nh("gtest"); std::cout << "in main " << std::endl; return 0; }
CMakeLists.txt

include_directories({PROJECT_SOURCE_DIR}/src) enable_testing() set(GTest_project src/Test/GTest/Test/MyClass.hpp) add_executable(gtest_ ${GTest_project} src/Test/GTest/GTestMain.cpp) target_link_libraries( gtest_ ${catkin_LIBRARIES} ) add_subdirectory(src/Test/GTest/Test)
内层目录
GTest/Test
下面的内容
MyClass.cpp

#include <gtest/gtest.h> #include "MyClass.hpp" TEST(test_my_class, get_age) { my_class myClass("Joel", 21); ASSERT_TRUE(myClass.get_age() == 21) << "age is not 16"; } TEST(test_my_class, get_name) { my_class myClass("Joel", 21); ASSERT_EQ(myClass.get_name(), "Joel") << "name is not Joel"; }
MyClass.hpp

#ifndef SRC_MYCLASS_HPP #define SRC_MYCLASS_HPP #pragma once #include <string> class my_class { public: my_class(const std::string& name, int age) { m_age = age; m_name = name; } public: int get_age() { return m_age; } std::string get_name() { return m_name; } private: int m_age; std::string m_name; }; #endif //SRC_MYCLASS_HPP
CMakeLists.txt

# 查找 GTest 库
find_package(GTest REQUIRED)
# GTest 的头文件
include_directories(${GTEST_INCLUDE_DIRS})
add_executable(test_my_class MyClass.cpp)
# 链接测试库
target_link_libraries( test_my_class
${GTEST_BOTH_LIBRARIES}
pthread)
# 添加到测试
gtest_discover_tests(test_my_class)
分类:
cartographer细节分析
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
2017-01-16 第四课4、ROS客户端
2017-01-16 第三课3、ROS的launch文件
2016-01-16 Monte carlo