error : uninitialized const member in struct ***

博客指出结构体中存在未初始化const成员的错误,即 'error : uninitialized const member in struct ***'。解决办法一是去掉const限制,二是考虑初始化赋值,具体采用哪种方式需根据业务要求决定。

目录

 

问题

解决


问题

error : uninitialized const member in struct ***

解决

声明const成员变量时需要初始化,如果想解决这个问题可以去掉const限制。

当然,这只是一种方式。或者考虑初始化赋值,这个就需要根据具体的业务要求来决定了。

 

 

 

80%] Building CXX object rotors_simulator/rotors_gazebo_plugins/CMakeFiles/rotors_gazebo_pressure_plugin.dir/src/gazebo_pressure_plugin.cpp.o In file included from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/logging.h:60:4: error: #error <glog/logging.h> was not included correctly. See the documentation for how to consume the library. 60 | # error <glog/logging.h> was not included correctly. See the documentation for how to consume the library. | ^~~~~ In file included from /usr/local/include/glog/logging.h:63, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/flags.h:45:4: error: #error <glog/flags.h> was not included correctly. See the documentation for how to consume the library. 45 | # error <glog/flags.h> was not included correctly. See the documentation for how to consume the library. | ^~~~~ In file included from /usr/local/include/glog/logging.h:77, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/log_severity.h:38:4: error: #error <glog/log_severity.h> was not included correctly. See the documentation for how to consume the library. 38 | # error <glog/log_severity.h> was not included correctly. See the documentation for how to consume the library. | ^~~~~ In file included from /usr/local/include/glog/logging.h:78, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/vlog_is_on.h:71:4: error: #error <glog/vlog_is_on.h> was not included correctly. See the documentation for how to consume the library. 71 | # error <glog/vlog_is_on.h> was not included correctly. See the documentation for how to consume the library. | ^~~~~ Scanning dependencies of target rotors_gazebo_odometry_plugin [ 80%] Building CXX object rotors_simulator/rotors_gazebo_plugins/CMakeFiles/rotors_gazebo_odometry_plugin.dir/src/gazebo_odometry_plugin.cpp.o [ 80%] Linking CXX shared library /home/zk/catkin_ws/devel/lib/libmav_control_interface.so [ 80%] Built target mav_control_interface Scanning dependencies of target rotors_gazebo_wind_plugin [ 80%] Building CXX object rotors_simulator/rotors_gazebo_plugins/CMakeFiles/rotors_gazebo_wind_plugin.dir/src/gazebo_wind_plugin.cpp.o [ 80%] Linking CXX executable /home/zk/catkin_ws/devel/lib/rotors_control/roll_pitch_yawrate_thrust_controller_node [ 80%] Built target roll_pitch_yawrate_thrust_controller_node Scanning dependencies of target rotors_gazebo_lidar_plugin In file included from /usr/local/include/glog/logging.h:63, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/flags.h:105:1: error: ‘GLOG_EXPORT’ does not name a type 105 | DECLARE_int32(logemaillevel); | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:105:1: error: ‘fLI::FLAGS_logemaillevel’ has not been declared 105 | DECLARE_int32(logemaillevel); | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:106:1: error: ‘GLOG_EXPORT’ does not name a type 106 | DECLARE_int32(logcleansecs); | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:106:1: error: ‘fLI::FLAGS_logcleansecs’ has not been declared 106 | DECLARE_int32(logcleansecs); | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:109:1: error: ‘GLOG_EXPORT’ does not name a type 109 | DECLARE_bool(drop_log_memory); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:109:1: error: ‘fLB::FLAGS_drop_log_memory’ has not been declared 109 | DECLARE_bool(drop_log_memory); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:111:1: error: ‘GLOG_EXPORT’ does not name a type 111 | DECLARE_string(alsologtoemail); | ^~~~~~~~~~~~~~ /usr/local/include/glog/flags.h:111:1: error: ‘fLS::FLAGS_alsologtoemail’ has not been declared 111 | DECLARE_string(alsologtoemail); | ^~~~~~~~~~~~~~ /usr/local/include/glog/flags.h:112:1: error: ‘GLOG_EXPORT’ does not name a type 112 | DECLARE_string(log_backtrace_at); | ^~~~~~~~~~~~~~ /usr/local/include/glog/flags.h:112:1: error: ‘fLS::FLAGS_log_backtrace_at’ has not been declared 112 | DECLARE_string(log_backtrace_at); | ^~~~~~~~~~~~~~ /usr/local/include/glog/flags.h:115:1: error: ‘GLOG_EXPORT’ does not name a type 115 | DECLARE_bool(timestamp_in_logfile_name); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:115:1: error: ‘fLB::FLAGS_timestamp_in_logfile_name’ has not been declared 115 | DECLARE_bool(timestamp_in_logfile_name); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:118:1: error: ‘GLOG_EXPORT’ does not name a type 118 | DECLARE_bool(logtostdout); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:118:1: error: ‘fLB::FLAGS_logtostdout’ has not been declared 118 | DECLARE_bool(logtostdout); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:121:1: error: ‘GLOG_EXPORT’ does not name a type 121 | DECLARE_bool(colorlogtostdout); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:121:1: error: ‘fLB::FLAGS_colorlogtostdout’ has not been declared 121 | DECLARE_bool(colorlogtostdout); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:124:1: error: ‘GLOG_EXPORT’ does not name a type 124 | DECLARE_bool(logtostderr); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:124:1: error: ‘fLB::FLAGS_logtostderr’ has not been declared 124 | DECLARE_bool(logtostderr); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:127:1: error: ‘GLOG_EXPORT’ does not name a type 127 | DECLARE_bool(alsologtostderr); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:127:1: error: ‘fLB::FLAGS_alsologtostderr’ has not been declared 127 | DECLARE_bool(alsologtostderr); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:130:1: error: ‘GLOG_EXPORT’ does not name a type 130 | DECLARE_bool(colorlogtostderr); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:130:1: error: ‘fLB::FLAGS_colorlogtostderr’ has not been declared 130 | DECLARE_bool(colorlogtostderr); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:134:1: error: ‘GLOG_EXPORT’ does not name a type 134 | DECLARE_int32(stderrthreshold); | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:134:1: error: ‘fLI::FLAGS_stderrthreshold’ has not been declared 134 | DECLARE_int32(stderrthreshold); | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:137:1: error: ‘GLOG_EXPORT’ does not name a type 137 | DECLARE_bool(log_file_header); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:137:1: error: ‘fLB::FLAGS_log_file_header’ has not been declared 137 | DECLARE_bool(log_file_header); | ^~~~~~~~~~~~ [ 81%] Building CXX object rotors_simulator/rotors_gazebo_plugins/CMakeFiles/rotors_gazebo_lidar_plugin.dir/src/external/gazebo_lidar_plugin.cpp.o /usr/local/include/glog/flags.h:140:1: error: ‘GLOG_EXPORT’ does not name a type 140 | DECLARE_bool(log_prefix); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:140:1: error: ‘fLB::FLAGS_log_prefix’ has not been declared 140 | DECLARE_bool(log_prefix); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:143:1: error: ‘GLOG_EXPORT’ does not name a type 143 | DECLARE_bool(log_year_in_prefix); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:143:1: error: ‘fLB::FLAGS_log_year_in_prefix’ has not been declared 143 | DECLARE_bool(log_year_in_prefix); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:147:1: error: ‘GLOG_EXPORT’ does not name a type 147 | DECLARE_int32(logbuflevel); | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:147:1: error: ‘fLI::FLAGS_logbuflevel’ has not been declared 147 | DECLARE_int32(logbuflevel); | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:150:1: error: ‘GLOG_EXPORT’ does not name a type 150 | DECLARE_int32(logbufsecs); | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:150:1: error: ‘fLI::FLAGS_logbufsecs’ has not been declared 150 | DECLARE_int32(logbufsecs); | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:154:1: error: ‘GLOG_EXPORT’ does not name a type 154 | DECLARE_int32(minloglevel); | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:154:1: error: ‘fLI::FLAGS_minloglevel’ has not been declared 154 | DECLARE_int32(minloglevel); | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:158:1: error: ‘GLOG_EXPORT’ does not name a type 158 | DECLARE_string(log_dir); | ^~~~~~~~~~~~~~ /usr/local/include/glog/flags.h:158:1: error: ‘fLS::FLAGS_log_dir’ has not been declared 158 | DECLARE_string(log_dir); | ^~~~~~~~~~~~~~ /usr/local/include/glog/flags.h:161:1: error: ‘GLOG_EXPORT’ does not name a type 161 | DECLARE_int32(logfile_mode); | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:161:1: error: ‘fLI::FLAGS_logfile_mode’ has not been declared 161 | DECLARE_int32(logfile_mode); | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:165:1: error: ‘GLOG_EXPORT’ does not name a type 165 | DECLARE_string(log_link); | ^~~~~~~~~~~~~~ /usr/local/include/glog/flags.h:165:1: error: ‘fLS::FLAGS_log_link’ has not been declared 165 | DECLARE_string(log_link); | ^~~~~~~~~~~~~~ /usr/local/include/glog/flags.h:167:1: error: ‘GLOG_EXPORT’ does not name a type 167 | DECLARE_int32(v); // in vlog_is_on.cc | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:167:1: error: ‘fLI::FLAGS_v’ has not been declared 167 | DECLARE_int32(v); // in vlog_is_on.cc | ^~~~~~~~~~~~~ /usr/local/include/glog/flags.h:169:1: error: ‘GLOG_EXPORT’ does not name a type 169 | DECLARE_string(vmodule); // also in vlog_is_on.cc | ^~~~~~~~~~~~~~ /usr/local/include/glog/flags.h:169:1: error: ‘fLS::FLAGS_vmodule’ has not been declared 169 | DECLARE_string(vmodule); // also in vlog_is_on.cc | ^~~~~~~~~~~~~~ /usr/local/include/glog/flags.h:172:1: error: ‘GLOG_EXPORT’ does not name a type 172 | DECLARE_uint32(max_log_size); | ^~~~~~~~~~~~~~ /usr/local/include/glog/flags.h:172:1: error: ‘fLU::FLAGS_max_log_size’ has not been declared 172 | DECLARE_uint32(max_log_size); | ^~~~~~~~~~~~~~ /usr/local/include/glog/flags.h:175:1: error: ‘GLOG_EXPORT’ does not name a type 175 | DECLARE_bool(stop_logging_if_full_disk); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:175:1: error: ‘fLB::FLAGS_stop_logging_if_full_disk’ has not been declared 175 | DECLARE_bool(stop_logging_if_full_disk); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:178:1: error: ‘GLOG_EXPORT’ does not name a type 178 | DECLARE_bool(log_utc_time); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:178:1: error: ‘fLB::FLAGS_log_utc_time’ has not been declared 178 | DECLARE_bool(log_utc_time); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:181:1: error: ‘GLOG_EXPORT’ does not name a type 181 | DECLARE_string(logmailer); | ^~~~~~~~~~~~~~ /usr/local/include/glog/flags.h:181:1: error: ‘fLS::FLAGS_logmailer’ has not been declared 181 | DECLARE_string(logmailer); | ^~~~~~~~~~~~~~ /usr/local/include/glog/flags.h:183:1: error: ‘GLOG_EXPORT’ does not name a type 183 | DECLARE_bool(symbolize_stacktrace); | ^~~~~~~~~~~~ /usr/local/include/glog/flags.h:183:1: error: ‘fLB::FLAGS_symbolize_stacktrace’ has not been declared 183 | DECLARE_bool(symbolize_stacktrace); | ^~~~~~~~~~~~ In file included from /usr/local/include/glog/logging.h:78, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/vlog_is_on.h:111:8: error: ‘GLOG_EXPORT’ does not name a type; did you mean ‘GLOG_ERROR’? 111 | extern GLOG_EXPORT int SetVLOGLevel(const char* module_pattern, int log_level); | ^~~~~~~~~~~ | GLOG_ERROR /usr/local/include/glog/vlog_is_on.h:130:8: error: ‘GLOG_EXPORT’ does not name a type; did you mean ‘GLOG_ERROR’? 130 | extern GLOG_EXPORT bool InitVLOG3__(SiteFlag* site_flag, | ^~~~~~~~~~~ | GLOG_ERROR In file included from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/logging.h:82:20: error: variable ‘google::GLOG_EXPORT google::LogMessageTime’ has initializer but incomplete type 82 | struct GLOG_EXPORT LogMessageTime { | ^~~~~~~~~~~~~~ /usr/local/include/glog/logging.h:83:19: error: expected ‘}’ before ‘;’ token 83 | LogMessageTime(); | ^ /usr/local/include/glog/logging.h:82:35: note: to match this ‘{’ 82 | struct GLOG_EXPORT LogMessageTime { | ^ /usr/local/include/glog/logging.h:84:3: error: ‘explicit’ outside class declaration 84 | explicit LogMessageTime(std::chrono::system_clock::time_point now); | ^~~~~~~~ /usr/local/include/glog/logging.h:86:61: error: non-member function ‘const time_point& google::when()’ cannot have cv-qualifier 86 | const std::chrono::system_clock::time_point& when() const noexcept { | ^~~~~~~~ /usr/local/include/glog/logging.h: In function ‘const time_point& google::when()’: /usr/local/include/glog/logging.h:87:12: error: ‘timestamp_’ was not declared in this scope; did you mean ‘timercmp’? 87 | return timestamp_; | ^~~~~~~~~~ | timercmp /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:89:19: error: non-member function ‘int google::sec()’ cannot have cv-qualifier 89 | int sec() const noexcept { return tm_.tm_sec; } | ^~~~~~~~ /usr/local/include/glog/logging.h: In function ‘int google::sec()’: /usr/local/include/glog/logging.h:89:37: error: ‘tm_’ was not declared in this scope; did you mean ‘tm’? 89 | int sec() const noexcept { return tm_.tm_sec; } | ^~~ | tm /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:90:21: error: non-member function ‘long int google::usec()’ cannot have cv-qualifier 90 | long usec() const noexcept { return usecs_.count(); } | ^~~~~~~~ /usr/local/include/glog/logging.h: In function ‘long int google::usec()’: /usr/local/include/glog/logging.h:90:39: error: ‘usecs_’ was not declared in this scope; did you mean ‘usec’? 90 | long usec() const noexcept { return usecs_.count(); } | ^~~~~~ | usec /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:91:20: error: non-member function ‘int google::min()’ cannot have cv-qualifier 91 | int(min)() const noexcept { return tm_.tm_min; } | ^~~~~~~~ /usr/local/include/glog/logging.h: In function ‘int google::min()’: /usr/local/include/glog/logging.h:91:38: error: ‘tm_’ was not declared in this scope; did you mean ‘tm’? 91 | int(min)() const noexcept { return tm_.tm_min; } | ^~~ | tm /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:92:20: error: non-member function ‘int google::hour()’ cannot have cv-qualifier 92 | int hour() const noexcept { return tm_.tm_hour; } | ^~~~~~~~ /usr/local/include/glog/logging.h: In function ‘int google::hour()’: /usr/local/include/glog/logging.h:92:38: error: ‘tm_’ was not declared in this scope; did you mean ‘tm’? 92 | int hour() const noexcept { return tm_.tm_hour; } | ^~~ | tm /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:93:19: error: non-member function ‘int google::day()’ cannot have cv-qualifier 93 | int day() const noexcept { return tm_.tm_mday; } | ^~~~~~~~ /usr/local/include/glog/logging.h: In function ‘int google::day()’: /usr/local/include/glog/logging.h:93:37: error: ‘tm_’ was not declared in this scope; did you mean ‘tm’? 93 | int day() const noexcept { return tm_.tm_mday; } | ^~~ | tm /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:94:21: error: non-member function ‘int google::month()’ cannot have cv-qualifier 94 | int month() const noexcept { return tm_.tm_mon; } | ^~~~~~~~ /usr/local/include/glog/logging.h: In function ‘int google::month()’: /usr/local/include/glog/logging.h:94:39: error: ‘tm_’ was not declared in this scope; did you mean ‘tm’? 94 | int month() const noexcept { return tm_.tm_mon; } | ^~~ | tm /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:95:20: error: non-member function ‘int google::year()’ cannot have cv-qualifier 95 | int year() const noexcept { return tm_.tm_year; } | ^~~~~~~~ /usr/local/include/glog/logging.h: In function ‘int google::year()’: /usr/local/include/glog/logging.h:95:38: error: ‘tm_’ was not declared in this scope; did you mean ‘tm’? 95 | int year() const noexcept { return tm_.tm_year; } | ^~~ | tm /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:96:25: error: non-member function ‘int google::dayOfWeek()’ cannot have cv-qualifier 96 | int dayOfWeek() const noexcept { return tm_.tm_wday; } | ^~~~~~~~ /usr/local/include/glog/logging.h: In function ‘int google::dayOfWeek()’: /usr/local/include/glog/logging.h:96:43: error: ‘tm_’ was not declared in this scope; did you mean ‘tm’? 96 | int dayOfWeek() const noexcept { return tm_.tm_wday; } | ^~~ | tm /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:97:25: error: non-member function ‘int google::dayInYear()’ cannot have cv-qualifier 97 | int dayInYear() const noexcept { return tm_.tm_yday; } | ^~~~~~~~ /usr/local/include/glog/logging.h: In function ‘int google::dayInYear()’: /usr/local/include/glog/logging.h:97:43: error: ‘tm_’ was not declared in this scope; did you mean ‘tm’? 97 | int dayInYear() const noexcept { return tm_.tm_yday; } | ^~~ | tm /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:98:19: error: non-member function ‘int google::dst()’ cannot have cv-qualifier 98 | int dst() const noexcept { return tm_.tm_isdst; } | ^~~~~~~~ /usr/local/include/glog/logging.h: In function ‘int google::dst()’: /usr/local/include/glog/logging.h:98:37: error: ‘tm_’ was not declared in this scope; did you mean ‘tm’? 98 | int dst() const noexcept { return tm_.tm_isdst; } | ^~~ | tm /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:99:42: error: non-member function ‘std::chrono::seconds google::gmtoffset()’ cannot have cv-qualifier 99 | std::chrono::seconds gmtoffset() const noexcept { return gmtoffset_; } | ^~~~~~~~ /usr/local/include/glog/logging.h: In function ‘std::chrono::seconds google::gmtoffset()’: /usr/local/include/glog/logging.h:99:60: error: ‘gmtoffset_’ was not declared in this scope; did you mean ‘gmtoffset’? 99 | std::chrono::seconds gmtoffset() const noexcept { return gmtoffset_; } | ^~~~~~~~~~ | gmtoffset /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:100:29: error: non-member function ‘const tm& google::tm()’ cannot have cv-qualifier 100 | const std::tm& tm() const noexcept { return tm_; } | ^~~~~~~~ /usr/local/include/glog/logging.h: In function ‘const tm& google::tm()’: /usr/local/include/glog/logging.h:100:47: error: ‘tm_’ was not declared in this scope; did you mean ‘tm’? 100 | const std::tm& tm() const noexcept { return tm_; } | ^~~ | tm /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:102:2: error: expected unqualified-id before ‘private’ 102 | private: | ^~~~~~~ /usr/local/include/glog/logging.h:110:1: error: expected declaration before ‘}’ token 110 | } // namespace google | ^ /usr/local/include/glog/logging.h:457:53: error: two or more data types in declaration of ‘InitGoogleLogging’ 457 | GLOG_EXPORT void InitGoogleLogging(const char* argv0); | ^ /usr/local/include/glog/logging.h:460:45: error: two or more data types in declaration of ‘IsGoogleLoggingInitialized’ 460 | GLOG_EXPORT bool IsGoogleLoggingInitialized(); | ^ /usr/local/include/glog/logging.h:463:40: error: two or more data types in declaration of ‘ShutdownGoogleLogging’ 463 | GLOG_EXPORT void ShutdownGoogleLogging(); | ^ /usr/local/include/glog/logging.h:477:61: error: two or more data types in declaration of ‘InstallPrefixFormatter’ 477 | void* data = nullptr); | ^ /usr/local/include/glog/logging.h:482:1: error: expected initializer before ‘InstallFailureFunction’ 482 | InstallFailureFunction(logging_fail_func_t fail_func); | ^~~~~~~~~~~~~~~~~~~~~~ /usr/local/include/glog/logging.h:485:70: error: two or more data types in declaration of ‘EnableLogCleaner’ 485 | GLOG_EXPORT void EnableLogCleaner(const std::chrono::minutes& overdue); | ^ /usr/local/include/glog/logging.h:486:36: error: two or more data types in declaration of ‘DisableLogCleaner’ 486 | GLOG_EXPORT void DisableLogCleaner(); | ^ /usr/local/include/glog/logging.h:487:74: error: two or more data types in declaration of ‘SetApplicationFingerprint’ 487 | GLOG_EXPORT void SetApplicationFingerprint(const std::string& fingerprint); | ^ /usr/local/include/glog/logging.h:611:72: error: two or more data types in declaration of ‘MakeCheckOpValueString’ 611 | GLOG_EXPORT void MakeCheckOpValueString(std::ostream* os, const char& v); | ^ /usr/local/include/glog/logging.h:613:79: error: two or more data types in declaration of ‘MakeCheckOpValueString’ 613 | GLOG_EXPORT void MakeCheckOpValueString(std::ostream* os, const signed char& v); | ^ /usr/local/include/glog/logging.h:616:63: error: two or more data types in declaration of ‘MakeCheckOpValueString’ 616 | const unsigned char& v); | ^ /usr/local/include/glog/logging.h:621:64: error: two or more data types in declaration of ‘MakeCheckOpValueString’ 621 | const std::nullptr_t& v); | ^ /usr/local/include/glog/logging.h:640:19: error: variable ‘google::GLOG_EXPORT google::logging::internal::CheckOpMessageBuilder’ has initializer but incomplete type 640 | class GLOG_EXPORT CheckOpMessageBuilder { | ^~~~~~~~~~~~~~~~~~~~~ /usr/local/include/glog/logging.h:641:2: error: expected primary-expression before ‘public’ 641 | public: | ^~~~~~ /usr/local/include/glog/logging.h:641:2: error: expected ‘}’ before ‘public’ /usr/local/include/glog/logging.h:640:41: note: to match this ‘{’ 640 | class GLOG_EXPORT CheckOpMessageBuilder { | ^ /usr/local/include/glog/logging.h:641:2: error: expected ‘,’ or ‘;’ before ‘public’ 641 | public: | ^~~~~~ /usr/local/include/glog/logging.h:645:25: error: expected class-name before ‘(’ token 645 | ~CheckOpMessageBuilder(); | ^ /usr/local/include/glog/logging.h: In function ‘std::ostream* google::logging::internal::ForVar1()’: /usr/local/include/glog/logging.h:647:36: error: ‘stream_’ was not declared in this scope 647 | std::ostream* ForVar1() { return stream_; } | ^~~~~~~ /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:653:2: error: expected unqualified-id before ‘private’ 653 | private: | ^~~~~~~ /usr/local/include/glog/logging.h: In function ‘std::unique_ptr<std::__cxx11::basic_string<char> > google::logging::MakeCheckOpString(const T1&, const T2&, const char*)’: /usr/local/include/glog/logging.h:660:3: error: ‘CheckOpMessageBuilder’ was not declared in this scope; did you mean ‘google::logging::internal::CheckOpMessageBuilder’? 660 | CheckOpMessageBuilder comb(exprtext); | ^~~~~~~~~~~~~~~~~~~~~ | google::logging::internal::CheckOpMessageBuilder /usr/local/include/glog/logging.h:640:19: note: ‘google::logging::internal::CheckOpMessageBuilder’ declared here 640 | class GLOG_EXPORT CheckOpMessageBuilder { | ^~~~~~~~~~~~~~~~~~~~~ /usr/local/include/glog/logging.h:661:26: error: ‘comb’ was not declared in this scope; did you mean ‘wctomb’? 661 | MakeCheckOpValueString(comb.ForVar1(), v1); | ^~~~ | wctomb /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:781:1: error: invalid declarator before ‘CheckstrcmptrueImpl’ 781 | DECLARE_CHECK_STROP_IMPL(strcmp, true) | ^~~~~~~~~~~~~~~~~~~~~~~~ /usr/local/include/glog/logging.h:782:1: error: invalid declarator before ‘CheckstrcmpfalseImpl’ 782 | DECLARE_CHECK_STROP_IMPL(strcmp, false) | ^~~~~~~~~~~~~~~~~~~~~~~~ /usr/local/include/glog/logging.h:783:1: error: invalid declarator before ‘CheckstrcasecmptrueImpl’ 783 | DECLARE_CHECK_STROP_IMPL(strcasecmp, true) | ^~~~~~~~~~~~~~~~~~~~~~~~ /usr/local/include/glog/logging.h:784:1: error: invalid declarator before ‘CheckstrcasecmpfalseImpl’ 784 | DECLARE_CHECK_STROP_IMPL(strcasecmp, false) | ^~~~~~~~~~~~~~~~~~~~~~~~ /usr/local/include/glog/logging.h:877:1: error: expected declaration before ‘}’ token 877 | } // namespace google | ^ /usr/local/include/glog/logging.h:1149:32: error: expected initializer before ‘:’ token 1149 | class GLOG_EXPORT LogStreamBuf : public std::streambuf { | ^ /usr/local/include/glog/logging.h:1166:23: error: aggregate ‘google::logging::internal::GLOG_NO_EXPORT google::logging::internal::LogMessageData’ has incomplete type and cannot be defined 1166 | struct GLOG_NO_EXPORT LogMessageData; | ^~~~~~~~~~~~~~ /usr/local/include/glog/logging.h:1179:19: error: variable ‘google::GLOG_EXPORT google::LogMessage’ has initializer but incomplete type 1179 | class GLOG_EXPORT LogMessage { | ^~~~~~~~~~ /usr/local/include/glog/logging.h:1180:2: error: expected primary-expression before ‘public’ 1180 | public: | ^~~~~~ /usr/local/include/glog/logging.h:1180:2: error: expected ‘}’ before ‘public’ /usr/local/include/glog/logging.h:1179:30: note: to match this ‘{’ 1179 | class GLOG_EXPORT LogMessage { | ^ /usr/local/include/glog/logging.h:1180:2: error: expected ‘,’ or ‘;’ before ‘public’ 1180 | public: | ^~~~~~ /usr/local/include/glog/logging.h:1197:31: error: expected initializer before ‘:’ token 1197 | class GLOG_EXPORT LogStream : public std::ostream { | ^ /usr/local/include/glog/logging.h:1243:2: error: expected unqualified-id before ‘public’ 1243 | public: | ^~~~~~ /usr/local/include/glog/logging.h:1248:14: error: ‘SendMethod’ has not been declared 1248 | SendMethod send_method); | ^~~~~~~~~~ /usr/local/include/glog/logging.h:1248:37: error: expected constructor, destructor, or type conversion before ‘;’ token 1248 | SendMethod send_method); | ^ /usr/local/include/glog/logging.h:1258:41: error: expected constructor, destructor, or type conversion before ‘;’ token 1258 | LogMessage(const char* file, int line); | ^ /usr/local/include/glog/logging.h:1265:63: error: expected constructor, destructor, or type conversion before ‘;’ token 1265 | LogMessage(const char* file, int line, LogSeverity severity); | ^ /usr/local/include/glog/logging.h:1271:36: error: expected constructor, destructor, or type conversion before ‘;’ token 1271 | bool also_send_to_log); | ^ /usr/local/include/glog/logging.h:1277:47: error: expected constructor, destructor, or type conversion before ‘;’ token 1277 | std::vector<std::string>* outvec); | ^ /usr/local/include/glog/logging.h:1283:35: error: expected constructor, destructor, or type conversion before ‘;’ token 1283 | std::string* message); | ^ /usr/local/include/glog/logging.h:1287:61: error: expected constructor, destructor, or type conversion before ‘;’ token 1287 | const logging::internal::CheckOpString& result); | ^ /usr/local/include/glog/logging.h:1289:32: error: expected constructor, destructor, or type conversion before ‘;’ token 1289 | ~LogMessage() noexcept(false); | ^ /usr/local/include/glog/logging.h:1298:23: error: uninitialized const ‘google::kMaxLogMessageLen’ [-fpermissive] 1298 | static const size_t kMaxLogMessageLen; | ^~~~~~~~~~~~~~~~~ /usr/local/include/glog/logging.h:1310:25: error: non-member function ‘int google::preserved_errno()’ cannot have cv-qualifier 1310 | int preserved_errno() const; | ^~~~~ /usr/local/include/glog/logging.h:1315:32: error: non-member function ‘google::LogSeverity google::severity()’ cannot have cv-qualifier 1315 | LogSeverity severity() const noexcept; | ^~~~~~~~ /usr/local/include/glog/logging.h:1316:20: error: non-member function ‘int google::line()’ cannot have cv-qualifier 1316 | int line() const noexcept; | ^~~~~~~~ /usr/local/include/glog/logging.h:1317:44: error: non-member function ‘const std::thread::id& google::thread_id()’ cannot have cv-qualifier 1317 | const std::thread::id& thread_id() const noexcept; | ^~~~~~~~ /usr/local/include/glog/logging.h:1318:32: error: non-member function ‘const char* google::fullname()’ cannot have cv-qualifier 1318 | const char* fullname() const noexcept; | ^~~~~~~~ /usr/local/include/glog/logging.h:1319:32: error: non-member function ‘const char* google::basename()’ cannot have cv-qualifier 1319 | const char* basename() const noexcept; | ^~~~~~~~ /usr/local/include/glog/logging.h:1320:9: error: ‘LogMessageTime’ does not name a type; did you mean ‘LogMessage’? 1320 | const LogMessageTime& time() const noexcept; | ^~~~~~~~~~~~~~ | LogMessage /usr/local/include/glog/logging.h:1322:20: error: ‘LogMessage’ does not name a type 1322 | LogMessage(const LogMessage&) = delete; | ^~~~~~~~~~ /usr/local/include/glog/logging.h:1322:33: error: expected constructor, destructor, or type conversion before ‘=’ token 1322 | LogMessage(const LogMessage&) = delete; | ^ /usr/local/include/glog/logging.h:1323:3: error: ‘LogMessage’ does not name a type 1323 | LogMessage& operator=(const LogMessage&) = delete; | ^~~~~~~~~~ /usr/local/include/glog/logging.h:1325:2: error: expected unqualified-id before ‘private’ 1325 | private: | ^~~~~~~ /usr/local/include/glog/logging.h:1346:22: error: ‘LogMessageData’ in namespace ‘google::logging::internal’ does not name a type 1346 | logging::internal::LogMessageData* allocated_; | ^~~~~~~~~~~~~~ /usr/local/include/glog/logging.h:1166:23: note: ‘google::logging::internal::LogMessageData’ declared here 1166 | struct GLOG_NO_EXPORT LogMessageData; | ^~~~~~~~~~~~~~ /usr/local/include/glog/logging.h:1347:22: error: ‘LogMessageData’ in namespace ‘google::logging::internal’ does not name a type 1347 | logging::internal::LogMessageData* data_; | ^~~~~~~~~~~~~~ /usr/local/include/glog/logging.h:1166:23: note: ‘google::logging::internal::LogMessageData’ declared here 1166 | struct GLOG_NO_EXPORT LogMessageData; | ^~~~~~~~~~~~~~ /usr/local/include/glog/logging.h:1348:3: error: ‘LogMessageTime’ does not name a type; did you mean ‘LogMessage’? 1348 | LogMessageTime time_; | ^~~~~~~~~~~~~~ | LogMessage /usr/local/include/glog/logging.h:1350:3: error: ‘friend’ used outside of class 1350 | friend class LogDestination; | ^~~~~~ | ------ /usr/local/include/glog/logging.h:1356:35: error: expected initializer before ‘:’ token 1356 | class GLOG_EXPORT LogMessageFatal : public LogMessage { | ^ /usr/local/include/glog/logging.h:1366:24: error: variable or field ‘LogAtLevel’ declared void 1366 | inline void LogAtLevel(LogSeverity severity, std::string const& msg) { | ^~~~~~~~~~~ /usr/local/include/glog/logging.h:1366:24: error: ‘LogSeverity’ was not declared in this scope; did you mean ‘google::LogSeverity’? 1366 | inline void LogAtLevel(LogSeverity severity, std::string const& msg) { | ^~~~~~~~~~~ | google::LogSeverity In file included from /usr/local/include/glog/logging.h:77, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/log_severity.h:62:6: note: ‘google::LogSeverity’ declared here 62 | enum LogSeverity { | ^~~~~~~~~~~ In file included from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/logging.h:1366:58: error: expected primary-expression before ‘const’ 1366 | inline void LogAtLevel(LogSeverity severity, std::string const& msg) { | ^~~~~ /usr/local/include/glog/logging.h:1380:25: error: expected initializer before ‘&’ token 1380 | GLOG_EXPORT std::ostream& operator<<(std::ostream& os, const Counter_t&); | ^ /usr/local/include/glog/logging.h:1383:35: error: expected initializer before ‘:’ token 1383 | class GLOG_EXPORT ErrnoLogMessage : public LogMessage { | ^ /usr/local/include/glog/logging.h: In function ‘T logging::internal::CheckNotNull(const char*, int, const char*, T&&)’: /usr/local/include/glog/logging.h:1414:5: error: there are no arguments to ‘LogMessageFatal’ that depend on a template parameter, so a declaration of ‘LogMessageFatal’ must be available [-fpermissive] 1414 | LogMessageFatal(file, line, std::make_unique<std::string>(names)); | ^~~~~~~~~~~~~~~ /usr/local/include/glog/logging.h:1414:5: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated) /usr/local/include/glog/logging.h: At global scope: /usr/local/include/glog/logging.h:1430:32: error: two or more data types in declaration of ‘FlushLogFiles’ 1430 | GLOG_EXPORT void FlushLogFiles(LogSeverity min_severity); | ^~~~~~~~~~~ /usr/local/include/glog/logging.h:1430:32: error: ‘LogSeverity’ was not declared in this scope; did you mean ‘google::LogSeverity’? 1430 | GLOG_EXPORT void FlushLogFiles(LogSeverity min_severity); | ^~~~~~~~~~~ | google::LogSeverity In file included from /usr/local/include/glog/logging.h:77, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/log_severity.h:62:6: note: ‘google::LogSeverity’ declared here 62 | enum LogSeverity { | ^~~~~~~~~~~ In file included from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/logging.h:1435:38: error: two or more data types in declaration of ‘FlushLogFilesUnsafe’ 1435 | GLOG_EXPORT void FlushLogFilesUnsafe(LogSeverity min_severity); | ^~~~~~~~~~~ /usr/local/include/glog/logging.h:1435:38: error: ‘LogSeverity’ was not declared in this scope; did you mean ‘google::LogSeverity’? 1435 | GLOG_EXPORT void FlushLogFilesUnsafe(LogSeverity min_severity); | ^~~~~~~~~~~ | google::LogSeverity In file included from /usr/local/include/glog/logging.h:77, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/log_severity.h:62:6: note: ‘google::LogSeverity’ declared here 62 | enum LogSeverity { | ^~~~~~~~~~~ In file included from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/logging.h:1442:36: error: two or more data types in declaration of ‘SetLogDestination’ 1442 | GLOG_EXPORT void SetLogDestination(LogSeverity severity, | ^~~~~~~~~~~ /usr/local/include/glog/logging.h:1442:36: error: ‘LogSeverity’ was not declared in this scope; did you mean ‘google::LogSeverity’? 1442 | GLOG_EXPORT void SetLogDestination(LogSeverity severity, | ^~~~~~~~~~~ | google::LogSeverity In file included from /usr/local/include/glog/logging.h:77, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/log_severity.h:62:6: note: ‘google::LogSeverity’ declared here 62 | enum LogSeverity { | ^~~~~~~~~~~ In file included from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/logging.h:1443:36: error: expected primary-expression before ‘const’ 1443 | const char* base_filename); | ^~~~~ /usr/local/include/glog/logging.h:1451:32: error: two or more data types in declaration of ‘SetLogSymlink’ 1451 | GLOG_EXPORT void SetLogSymlink(LogSeverity severity, | ^~~~~~~~~~~ /usr/local/include/glog/logging.h:1451:32: error: ‘LogSeverity’ was not declared in this scope; did you mean ‘google::LogSeverity’? 1451 | GLOG_EXPORT void SetLogSymlink(LogSeverity severity, | ^~~~~~~~~~~ | google::LogSeverity In file included from /usr/local/include/glog/logging.h:77, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/log_severity.h:62:6: note: ‘google::LogSeverity’ declared here 62 | enum LogSeverity { | ^~~~~~~~~~~ In file included from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/logging.h:1452:32: error: expected primary-expression before ‘const’ 1452 | const char* symlink_basename); | ^~~~~ /usr/local/include/glog/logging.h:1459:19: error: variable ‘GLOG_EXPORT LogSink’ has initializer but incomplete type 1459 | class GLOG_EXPORT LogSink { | ^~~~~~~ /usr/local/include/glog/logging.h:1460:2: error: expected primary-expression before ‘public’ 1460 | public: | ^~~~~~ /usr/local/include/glog/logging.h:1460:2: error: expected ‘}’ before ‘public’ /usr/local/include/glog/logging.h:1459:27: note: to match this ‘{’ 1459 | class GLOG_EXPORT LogSink { | ^ /usr/local/include/glog/logging.h:1460:2: error: expected ‘,’ or ‘;’ before ‘public’ 1460 | public: | ^~~~~~ /usr/local/include/glog/logging.h:1466:3: error: ‘virtual’ outside class declaration 1466 | virtual void send(LogSeverity severity, const char* full_filename, | ^~~~~~~ /usr/local/include/glog/logging.h:1466:21: error: variable or field ‘send’ declared void 1466 | virtual void send(LogSeverity severity, const char* full_filename, | ^~~~~~~~~~~ /usr/local/include/glog/logging.h:1466:21: error: ‘LogSeverity’ was not declared in this scope; did you mean ‘google::LogSeverity’? 1466 | virtual void send(LogSeverity severity, const char* full_filename, | ^~~~~~~~~~~ | google::LogSeverity In file included from /usr/local/include/glog/logging.h:77, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/log_severity.h:62:6: note: ‘google::LogSeverity’ declared here 62 | enum LogSeverity { | ^~~~~~~~~~~ In file included from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/logging.h:1466:43: error: expected primary-expression before ‘const’ 1466 | virtual void send(LogSeverity severity, const char* full_filename, | ^~~~~ /usr/local/include/glog/logging.h:1467:21: error: expected primary-expression before ‘const’ 1467 | const char* base_filename, int line, | ^~~~~ /usr/local/include/glog/logging.h:1467:48: error: expected primary-expression before ‘int’ 1467 | const char* base_filename, int line, | ^~~ /usr/local/include/glog/logging.h:1468:21: error: expected primary-expression before ‘const’ 1468 | const LogMessageTime& time, const char* message, | ^~~~~ /usr/local/include/glog/logging.h:1468:49: error: expected primary-expression before ‘const’ 1468 | const LogMessageTime& time, const char* message, | ^~~~~ /usr/local/include/glog/logging.h:1469:28: error: expected primary-expression before ‘message_len’ 1469 | size_t message_len) = 0; | ^~~~~~~~~~~ /usr/local/include/glog/logging.h:1484:3: error: ‘virtual’ outside class declaration 1484 | virtual void WaitTillSent(); | ^~~~~~~ /usr/local/include/glog/logging.h:1488:31: error: ‘LogSeverity’ was not declared in this scope; did you mean ‘google::LogSeverity’? 1488 | static std::string ToString(LogSeverity severity, const char* file, int line, | ^~~~~~~~~~~ | google::LogSeverity In file included from /usr/local/include/glog/logging.h:77, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/log_severity.h:62:6: note: ‘google::LogSeverity’ declared here 62 | enum LogSeverity { | ^~~~~~~~~~~ In file included from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/logging.h:1488:53: error: expected primary-expression before ‘const’ 1488 | static std::string ToString(LogSeverity severity, const char* file, int line, | ^~~~~ /usr/local/include/glog/logging.h:1488:71: error: expected primary-expression before ‘int’ 1488 | static std::string ToString(LogSeverity severity, const char* file, int line, | ^~~ /usr/local/include/glog/logging.h:1489:31: error: expected primary-expression before ‘const’ 1489 | const LogMessageTime& time, const char* message, | ^~~~~ /usr/local/include/glog/logging.h:1489:59: error: expected primary-expression before ‘const’ 1489 | const LogMessageTime& time, const char* message, | ^~~~~ /usr/local/include/glog/logging.h:1490:38: error: expected primary-expression before ‘message_len’ 1490 | size_t message_len); | ^~~~~~~~~~~ /usr/local/include/glog/logging.h:1491:1: error: expected declaration before ‘}’ token 1491 | }; | ^ /usr/local/include/glog/logging.h:1494:29: error: two or more data types in declaration of ‘AddLogSink’ 1494 | GLOG_EXPORT void AddLogSink(LogSink* destination); | ^~~~~~~ /usr/local/include/glog/logging.h:1494:38: error: ‘destination’ was not declared in this scope 1494 | GLOG_EXPORT void AddLogSink(LogSink* destination); | ^~~~~~~~~~~ /usr/local/include/glog/logging.h:1495:32: error: two or more data types in declaration of ‘RemoveLogSink’ 1495 | GLOG_EXPORT void RemoveLogSink(LogSink* destination); | ^~~~~~~ /usr/local/include/glog/logging.h:1495:41: error: ‘destination’ was not declared in this scope 1495 | GLOG_EXPORT void RemoveLogSink(LogSink* destination); | ^~~~~~~~~~~ /usr/local/include/glog/logging.h:1503:72: error: two or more data types in declaration of ‘SetLogFilenameExtension’ 1503 | GLOG_EXPORT void SetLogFilenameExtension(const char* filename_extension); | ^ /usr/local/include/glog/logging.h:1510:35: error: two or more data types in declaration of ‘SetStderrLogging’ 1510 | GLOG_EXPORT void SetStderrLogging(LogSeverity min_severity); | ^~~~~~~~~~~ /usr/local/include/glog/logging.h:1510:35: error: ‘LogSeverity’ was not declared in this scope; did you mean ‘google::LogSeverity’? 1510 | GLOG_EXPORT void SetStderrLogging(LogSeverity min_severity); | ^~~~~~~~~~~ | google::LogSeverity In file included from /usr/local/include/glog/logging.h:77, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/log_severity.h:62:6: note: ‘google::LogSeverity’ declared here 62 | enum LogSeverity { | ^~~~~~~~~~~ In file included from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/logging.h:1515:30: error: two or more data types in declaration of ‘LogToStderr’ 1515 | GLOG_EXPORT void LogToStderr(); | ^ /usr/local/include/glog/logging.h:1523:34: error: two or more data types in declaration of ‘SetEmailLogging’ 1523 | GLOG_EXPORT void SetEmailLogging(LogSeverity min_severity, | ^~~~~~~~~~~ /usr/local/include/glog/logging.h:1523:34: error: ‘LogSeverity’ was not declared in this scope; did you mean ‘google::LogSeverity’? 1523 | GLOG_EXPORT void SetEmailLogging(LogSeverity min_severity, | ^~~~~~~~~~~ | google::LogSeverity In file included from /usr/local/include/glog/logging.h:77, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/log_severity.h:62:6: note: ‘google::LogSeverity’ declared here 62 | enum LogSeverity { | ^~~~~~~~~~~ In file included from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/logging.h:1524:34: error: expected primary-expression before ‘const’ 1524 | const char* addresses); | ^~~~~ /usr/local/include/glog/logging.h:1529:44: error: two or more data types in declaration of ‘SendEmail’ 1529 | const char* body); | ^ /usr/local/include/glog/logging.h:1531:43: error: invalid declarator before ‘&’ token 1531 | GLOG_EXPORT const std::vector<std::string>& GetLoggingDirectories(); | ^ /usr/local/include/glog/logging.h:1536:38: error: two or more data types in declaration of ‘ReprintFatalMessage’ 1536 | GLOG_EXPORT void ReprintFatalMessage(); | ^ /usr/local/include/glog/logging.h:1545:52: error: ‘uint64’ has not been declared 1545 | GLOG_EXPORT void TruncateLogFile(const char* path, uint64 limit, uint64 keep); | ^~~~~~ /usr/local/include/glog/logging.h:1545:66: error: ‘uint64’ has not been declared 1545 | GLOG_EXPORT void TruncateLogFile(const char* path, uint64 limit, uint64 keep); | ^~~~~~ /usr/local/include/glog/logging.h:1545:77: error: two or more data types in declaration of ‘TruncateLogFile’ 1545 | GLOG_EXPORT void TruncateLogFile(const char* path, uint64 limit, uint64 keep); | ^ /usr/local/include/glog/logging.h:1550:39: error: two or more data types in declaration of ‘TruncateStdoutStderr’ 1550 | GLOG_EXPORT void TruncateStdoutStderr(); | ^ /usr/local/include/glog/logging.h:1554:44: error: two or more data types in declaration of ‘GetLogSeverityName’ 1554 | GLOG_EXPORT const char* GetLogSeverityName(LogSeverity severity); | ^~~~~~~~~~~ /usr/local/include/glog/logging.h:1554:44: error: ‘LogSeverity’ was not declared in this scope; did you mean ‘google::LogSeverity’? 1554 | GLOG_EXPORT const char* GetLogSeverityName(LogSeverity severity); | ^~~~~~~~~~~ | google::LogSeverity In file included from /usr/local/include/glog/logging.h:77, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/log_severity.h:62:6: note: ‘google::LogSeverity’ declared here 62 | enum LogSeverity { | ^~~~~~~~~~~ In file included from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/logging.h:1569:19: error: variable ‘GLOG_EXPORT base::Logger’ has initializer but incomplete type 1569 | class GLOG_EXPORT Logger { | ^~~~~~ /usr/local/include/glog/logging.h:1570:2: error: expected primary-expression before ‘public’ 1570 | public: | ^~~~~~ /usr/local/include/glog/logging.h:1570:2: error: expected ‘}’ before ‘public’ /usr/local/include/glog/logging.h:1569:26: note: to match this ‘{’ 1569 | class GLOG_EXPORT Logger { | ^ /usr/local/include/glog/logging.h:1570:2: error: expected ‘,’ or ‘;’ before ‘public’ 1570 | public: | ^~~~~~ /usr/local/include/glog/logging.h:1581:3: error: ‘virtual’ outside class declaration 1581 | virtual void Write(bool force_flush, | ^~~~~~~ /usr/local/include/glog/logging.h:1581:16: error: function ‘void base::Write(bool, const time_point&, const char*, size_t)’ is initialized like a variable 1581 | virtual void Write(bool force_flush, | ^~~~~ /usr/local/include/glog/logging.h:1586:3: error: ‘virtual’ outside class declaration 1586 | virtual void Flush() = 0; | ^~~~~~~ /usr/local/include/glog/logging.h:1586:16: error: function ‘void base::Flush()’ is initialized like a variable 1586 | virtual void Flush() = 0; | ^~~~~ /usr/local/include/glog/logging.h:1591:11: error: ‘uint32’ does not name a type; did you mean ‘uint32_t’? 1591 | virtual uint32 LogSize() = 0; | ^~~~~~ | uint32_t /usr/local/include/glog/logging.h:1597:26: error: expected initializer before ‘*’ token 1597 | extern GLOG_EXPORT Logger* GetLogger(LogSeverity level); | ^ /usr/local/include/glog/logging.h:1602:35: error: two or more data types in declaration of ‘SetLogger’ 1602 | extern GLOG_EXPORT void SetLogger(LogSeverity level, Logger* logger); | ^~~~~~~~~~~ /usr/local/include/glog/logging.h:1602:35: error: ‘LogSeverity’ was not declared in this scope; did you mean ‘google::LogSeverity’? 1602 | extern GLOG_EXPORT void SetLogger(LogSeverity level, Logger* logger); | ^~~~~~~~~~~ | google::LogSeverity In file included from /usr/local/include/glog/logging.h:77, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/log_severity.h:62:6: note: ‘google::LogSeverity’ declared here 62 | enum LogSeverity { | ^~~~~~~~~~~ In file included from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/include/rotors_gazebo_plugins/gazebo_pressure_plugin.h:22, from /home/zk/catkin_ws/src/rotors_simulator/rotors_gazebo_plugins/src/gazebo_pressure_plugin.cpp:18: /usr/local/include/glog/logging.h:1602:54: error: ‘Logger’ was not declared in this scope; did you mean ‘base::Logger’? 1602 | extern GLOG_EXPORT void SetLogger(LogSeverity level, Logger* logger); | ^~~~~~ | base::Logger /usr/local/include/glog/logging.h:1569:19: note: ‘base::Logger’ declared here 1569 | class GLOG_EXPORT Logger { | ^~~~~~ /usr/local/include/glog/logging.h:1602:62: error: ‘logger’ was not declared in this scope 1602 | extern GLOG_EXPORT void SetLogger(LogSeverity level, Logger* logger); | ^~~~~~ /usr/local/include/glog/logging.h:1604:1: error: expected declaration before ‘}’ token 1604 | } // namespace base | ^ /usr/local/include/glog/logging.h:1607:30: error: expected initializer before ‘:’ token 1607 | class GLOG_EXPORT NullStream : public LogMessage::LogStream { | ^ /usr/local/include/glog/logging.h:1632:8: error: ‘NullStream’ does not name a type 1632 | inline NullStream& operator<<(NullStream& str, const T&) { | ^~~~~~~~~~ /usr/local/include/glog/logging.h:1638:35: error: expected initializer before ‘:’ token 1638 | class GLOG_EXPORT NullStreamFatal : public NullStream { | ^ /usr/local/include/glog/logging.h:1662:46: error: two or more data types in declaration of ‘InstallFailureSignalHandler’ 1662 | GLOG_EXPORT void InstallFailureSignalHandler(); | ^ /usr/local/include/glog/logging.h:1665:50: error: two or more data types in declaration of ‘IsFailureSignalHandlerInstalled’ 1665 | GLOG_EXPORT bool IsFailureSignalHandlerInstalled(); | ^ /usr/local/include/glog/logging.h:1672:66: error: two or more data types in declaration of ‘InstallFailureWriter’ 1672 | size_t size)); | ^ /usr/local/include/glog/logging.h:1675:25: error: expected initializer before ‘GetStackTrace’ 1675 | GLOG_EXPORT std::string GetStackTrace(); | ^~~~~~~~~~~~~ /usr/local/include/glog/logging.h:1677:1: error: expected declaration before ‘}’ token 1677 | } // namespace google | ^
最新发布
09-03
#include "../include/include/realtime_utils/realtime_utils.hpp" #include <rclcpp/rclcpp.hpp> #include <std_msgs/msg/float64.hpp> #include <chrono> #include <thread> #include <vector> #include <string> #include <memory> #include <atomic> #include <limits> using namespace std::chrono_literals; // 原子操作辅助工具 namespace atomic_utils { template<typename T> void atomic_update_max(std::atomic<T>& atomic_var, T value) { T current = atomic_var.load(); while (value > current && !atomic_var.compare_exchange_weak(current, value)) {} } template<typename T> void atomic_update_min(std::atomic<T>& atomic_var, T value) { T current = atomic_var.load(); while (value < current && !atomic_var.compare_exchange_weak(current, value)) {} } } // 多线程订阅者节点 class MultiThreadSubscriber : public rclcpp::Node { public: // 线程统计结构(全原子操作) struct ThreadStats { std::atomic<uint64_t> message_count{0}; std::atomic<uint64_t> total_latency{0}; // 改为uint64避免溢出 std::atomic<int64_t> max_latency{0}; std::atomic<int64_t> min_latency{std::numeric_limits<int64_t>::max()}; // 原子重置方法 void reset() { message_count = 0; total_latency = 0; max_latency = 0; min_latency = std::numeric_limits<int64_t>::max(); } }; // 消息数据结构 struct MessageData { double value; std::chrono::steady_clock::time_point receive_time; int thread_id; }; // 构造函数 MultiThreadSubscriber() : Node("multithread_subscriber") { // 参数声明 declare_parameter("thread_count", 4); declare_parameter("process_time_us", 200); // 获取参数 int thread_count = get_parameter("thread_count").as_int(); int process_time = get_parameter("process_time_us").as_int(); thread_stats_.resize(thread_count); // 创建订阅线程 for (int i = 0; i < thread_count; ++i) { threads_.emplace_back(&MultiThreadSubscriber::subscriber_loop, this, i, process_time); } // 创建低优先级监控线程 monitor_thread_ = std::thread([this]() { pthread_setname_np(pthread_self(), "monitor_thread"); realtime_utils::RTThread::set_current_thread_priority(SCHED_OTHER, 0); monitor_loop(); }); } // 析构函数 ~MultiThreadSubscriber() { running_ = false; for (auto& thread : threads_) { if (thread.joinable()) thread.join(); } if (monitor_thread_.joinable()) monitor_thread_.join(); } private: // 订阅线程主循环 void subscriber_loop(int thread_id, int process_time) { // 设置高实时优先级 std::string thread_name = "sub_thread_" + std::to_string(thread_id); pthread_setname_np(pthread_self(), thread_name.c_str()); if (!realtime_utils::RTThread::set_current_thread_priority( SCHED_FIFO, 90 - thread_id)) { // 提高优先级 RCLCPP_ERROR(get_logger(), "Thread %d failed to set real-time priority", thread_id); } // 创建专属话题 auto topic_name = "control_topic_" + std::to_string(thread_id); auto qos = rclcpp::QoS(100).reliable().durability_volatile(); // 增加队列大小 // 创建订阅器 auto sub = create_subscription<std_msgs::msg::Float64>( topic_name, qos, [this, thread_id](const std_msgs::msg::Float64::SharedPtr msg) { MessageData data; data.value = msg->data; data.receive_time = std::chrono::steady_clock::now(); data.thread_id = thread_id; if (!message_buffer_.push(data)) { RCLCPP_WARN_THROTTLE(get_logger(), *get_clock(), 1000, "Thread %d buffer full, message dropped", thread_id); } }); // 主处理循环 while (rclcpp::ok() && running_) { MessageData data; if (message_buffer_.pop(data)) { // 模拟处理耗时 std::this_thread::sleep_for(std::chrono::microseconds(process_time)); // 计算端到端延迟 auto latency = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::steady_clock::now() - data.receive_time).count(); // 无锁更新统计 update_thread_stats(data.thread_id, latency); } else { std::this_thread::sleep_for(100us); // 更短的休眠 } } } // 无锁统计更新 void update_thread_stats(size_t thread_id, int64_t latency) { if (thread_id >= thread_stats_.size()) return; auto& stats = thread_stats_[thread_id]; stats.message_count++; stats.total_latency += latency; atomic_utils::atomic_update_max(stats.max_latency, latency); atomic_utils::atomic_update_min(stats.min_latency, latency); } // 监控循环(无锁) void monitor_loop() { auto last_print = std::chrono::steady_clock::now(); while (rclcpp::ok() && running_) { std::this_thread::sleep_for(5s); // 降低输出频率 // 原子获取统计快照 std::vector<ThreadStats> snapshot; for (auto& stats : thread_stats_) { ThreadStats s; s.message_count = stats.message_count.exchange(0); s.total_latency = stats.total_latency.exchange(0); s.max_latency = stats.max_latency.exchange(0); s.min_latency = stats.min_latency.exchange(std::numeric_limits<int64_t>::max()); snapshot.push_back(s); } // 输出统计(非实时上下文) print_stats(snapshot); } } // 打印统计(无锁) void print_stats(const std::vector<ThreadStats>& snapshot) { RCLCPP_INFO(get_logger(), "\n=== Subscriber Threads Stats ==="); for (size_t i = 0; i < snapshot.size(); ++i) { const auto& stats = snapshot[i]; if (stats.message_count == 0) continue; double avg_latency = static_cast<double>(stats.total_latency) / stats.message_count; RCLCPP_INFO(get_logger(), "Thread %zu: %lu msgs | Avg: %.2f us | Max: %ld us | Min: %ld us", i, stats.message_count.load(), avg_latency, stats.max_latency.load(), stats.min_latency.load()); } } // 成员变量 std::vector<std::thread> threads_; std::thread monitor_thread_; std::atomic<bool> running_{true}; realtime_utils::LockFreeRingBuffer<MessageData, 20000> message_buffer_; // 增大缓冲区 std::vector<ThreadStats> thread_stats_; // 无锁统计 }; int main(int argc, char** argv) { rclcpp::init(argc, argv); auto node = std::make_shared<MultiThreadSubscriber>(); rclcpp::spin(node); rclcpp::shutdown(); return 0; } #include "../include/include/realtime_utils/realtime_utils.hpp" #include <rclcpp/rclcpp.hpp> #include <std_msgs/msg/float64.hpp> #include <chrono> #include <thread> #include <vector> #include <string> #include <memory> #include <atomic> #include <limits> using namespace std::chrono_literals; // 原子操作辅助工具 namespace atomic_utils { template<typename T> void atomic_update_max(std::atomic<T>& atomic_var, T value) { T current = atomic_var.load(); while (value > current && !atomic_var.compare_exchange_weak(current, value)) {} } template<typename T> void atomic_update_min(std::atomic<T>& atomic_var, T value) { T current = atomic_var.load(); while (value < current && !atomic_var.compare_exchange_weak(current, value)) {} } } // 多线程发布者节点 class MultiThreadPublisher : public rclcpp::Node { public: // 线程统计结构(全原子操作) struct ThreadStats { std::atomic<uint64_t> message_count{0}; std::atomic<uint64_t> total_latency{0}; // 改为uint64避免溢出 std::atomic<int64_t> max_latency{0}; std::atomic<int64_t> min_latency{std::numeric_limits<int64_t>::max()}; // 原子重置方法 void reset() { message_count = 0; total_latency = 0; max_latency = 0; min_latency = std::numeric_limits<int64_t>::max(); } }; // 构造函数 MultiThreadPublisher() : Node("multithread_publisher") { // 参数声明 declare_parameter("thread_count", 4); declare_parameter("frequency", 500.0); // 获取参数 int thread_count = get_parameter("thread_count").as_int(); double frequency = get_parameter("frequency").as_double(); thread_stats_.resize(thread_count); // 初始化统计容器 // 创建发布线程 for (int i = 0; i < thread_count; ++i) { threads_.emplace_back(&MultiThreadPublisher::publisher_loop, this, i, frequency); } // 创建低优先级监控线程 monitor_thread_ = std::thread([this]() { pthread_setname_np(pthread_self(), "monitor_thread"); realtime_utils::RTThread::set_current_thread_priority(SCHED_OTHER, 0); monitor_loop(); }); } // 析构函数 ~MultiThreadPublisher() { running_ = false; for (auto& thread : threads_) { if (thread.joinable()) thread.join(); } if (monitor_thread_.joinable()) monitor_thread_.join(); } private: // 发布线程主循环 void publisher_loop(int thread_id, double frequency) { // 设置线程名和实时优先级 std::string thread_name = "pub_thread_" + std::to_string(thread_id); pthread_setname_np(pthread_self(), thread_name.c_str()); if (!realtime_utils::RTThread::set_current_thread_priority( SCHED_FIFO, 90 - thread_id)) { // 提高优先级 RCLCPP_ERROR(get_logger(), "Thread %d failed to set real-time priority", thread_id); } // 创建专属话题和发布器 auto topic_name = "control_topic_" + std::to_string(thread_id); auto qos = rclcpp::QoS(100).reliable().durability_volatile(); // 增加队列大小 auto pub = create_publisher<std_msgs::msg::Float64>(topic_name, qos); // 计算发布周期 const auto period = std::chrono::nanoseconds(static_cast<int64_t>(1e9 / frequency)); auto start_time = std::chrono::steady_clock::now(); uint64_t count = 0; // 复用消息对象 auto msg = std::make_shared<std_msgs::msg::Float64>(); msg->data = thread_id; while (rclcpp::ok() && running_) { auto next_time = start_time + count * period; std::this_thread::sleep_until(next_time); msg->data = count; pub->publish(*msg); auto latency = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::steady_clock::now() - next_time).count(); // 无锁更新统计 update_thread_stats(thread_id, latency); count++; } } // 无锁统计更新 void update_thread_stats(size_t thread_id, int64_t latency) { if (thread_id >= thread_stats_.size()) return; auto& stats = thread_stats_[thread_id]; stats.message_count++; stats.total_latency += latency; atomic_utils::atomic_update_max(stats.max_latency, latency); atomic_utils::atomic_update_min(stats.min_latency, latency); } // 监控循环(无锁) void monitor_loop() { auto last_print = std::chrono::steady_clock::now(); while (rclcpp::ok() && running_) { std::this_thread::sleep_for(5s); // 降低输出频率 // 原子获取统计快照 std::vector<ThreadStats> snapshot; for (auto& stats : thread_stats_) { ThreadStats s; s.message_count = stats.message_count.exchange(0); s.total_latency = stats.total_latency.exchange(0); s.max_latency = stats.max_latency.exchange(0); s.min_latency = stats.min_latency.exchange(std::numeric_limits<int64_t>::max()); snapshot.push_back(s); } // 输出统计(非实时上下文) print_stats(snapshot); } } // 打印统计(无锁) void print_stats(const std::vector<ThreadStats>& snapshot) { RCLCPP_INFO(get_logger(), "\n=== Publisher Threads Stats ==="); for (size_t i = 0; i < snapshot.size(); ++i) { const auto& stats = snapshot[i]; if (stats.message_count == 0) continue; double avg_latency = static_cast<double>(stats.total_latency) / stats.message_count; RCLCPP_INFO(get_logger(), "Thread %zu: %lu msgs | Avg: %.2f us | Max: %ld us | Min: %ld us", i, stats.message_count.load(), avg_latency, stats.max_latency.load(), stats.min_latency.load()); } } // 成员变量 std::vector<std::thread> threads_; std::thread monitor_thread_; std::atomic<bool> running_{true}; std::vector<ThreadStats> thread_stats_; // 无锁统计 }; int main(int argc, char** argv) { rclcpp::init(argc, argv); if (getuid() != 0) { RCLCPP_ERROR(rclcpp::get_logger("main"), "This program requires root privileges for real-time scheduling"); return 1; } auto node = std::make_shared<MultiThreadPublisher>(); rclcpp::spin(node); rclcpp::shutdown(); return 0; } 报错: --- stderr: realtime_demo /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_subscriber.cpp: In member function ‘void MultiThreadSubscriber::monitor_loop()’: /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_subscriber.cpp:154:14: warning: variable ‘last_print’ set but not used [-Wunused-but-set-variable] 154 | auto last_print = std::chrono::steady_clock::now(); | ^~~~~~~~~~ /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_publisher.cpp: In member function ‘void MultiThreadPublisher::monitor_loop()’: /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_publisher.cpp:140:14: warning: variable ‘last_print’ set but not used [-Wunused-but-set-variable] 140 | auto last_print = std::chrono::steady_clock::now(); | ^~~~~~~~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/c++allocator.h:33, from /usr/include/c++/11/bits/allocator.h:46, from /usr/include/c++/11/memory:64, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/rclcpp.hpp:153, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/../include/include/realtime_utils/realtime_utils.hpp:3, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_subscriber.cpp:1: /usr/include/c++/11/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = MultiThreadSubscriber::ThreadStats; _Args = {const MultiThreadSubscriber::ThreadStats&}; _Tp = MultiThreadSubscriber::ThreadStats]’: /usr/include/c++/11/bits/alloc_traits.h:516:17: required from ‘static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = MultiThreadSubscriber::ThreadStats; _Args = {const MultiThreadSubscriber::ThreadStats&}; _Tp = MultiThreadSubscriber::ThreadStats; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<MultiThreadSubscriber::ThreadStats>]’ /usr/include/c++/11/bits/stl_vector.h:1192:30: required from ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = MultiThreadSubscriber::ThreadStats; _Alloc = std::allocator<MultiThreadSubscriber::ThreadStats>; std::vector<_Tp, _Alloc>::value_type = MultiThreadSubscriber::ThreadStats]’ /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_subscriber.cpp:167:35: required from here /usr/include/c++/11/ext/new_allocator.h:162:11: error: use of deleted function ‘MultiThreadSubscriber::ThreadStats::ThreadStats(const MultiThreadSubscriber::ThreadStats&)’ 162 | { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_subscriber.cpp:35:12: note: ‘MultiThreadSubscriber::ThreadStats::ThreadStats(const MultiThreadSubscriber::ThreadStats&)’ is implicitly deleted because the default definition would be ill-formed: 35 | struct ThreadStats { | ^~~~~~~~~~~ /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_subscriber.cpp:35:12: error: use of deleted function ‘std::atomic<long unsigned int>::atomic(const std::atomic<long unsigned int>&)’ In file included from /usr/include/c++/11/future:41, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/executors.hpp:18, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/rclcpp.hpp:155, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/../include/include/realtime_utils/realtime_utils.hpp:3, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_subscriber.cpp:1: /usr/include/c++/11/atomic:898:7: note: declared here 898 | atomic(const atomic&) = delete; | ^~~~~~ /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_subscriber.cpp:35:12: error: use of deleted function ‘std::atomic<long unsigned int>::atomic(const std::atomic<long unsigned int>&)’ 35 | struct ThreadStats { | ^~~~~~~~~~~ In file included from /usr/include/c++/11/future:41, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/executors.hpp:18, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/rclcpp.hpp:155, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/../include/include/realtime_utils/realtime_utils.hpp:3, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_subscriber.cpp:1: /usr/include/c++/11/atomic:898:7: note: declared here 898 | atomic(const atomic&) = delete; | ^~~~~~ /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_subscriber.cpp:35:12: error: use of deleted function ‘std::atomic<long int>::atomic(const std::atomic<long int>&)’ 35 | struct ThreadStats { | ^~~~~~~~~~~ In file included from /usr/include/c++/11/future:41, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/executors.hpp:18, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/rclcpp.hpp:155, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/../include/include/realtime_utils/realtime_utils.hpp:3, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_subscriber.cpp:1: /usr/include/c++/11/atomic:875:7: note: declared here 875 | atomic(const atomic&) = delete; | ^~~~~~ /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_subscriber.cpp:35:12: error: use of deleted function ‘std::atomic<long int>::atomic(const std::atomic<long int>&)’ 35 | struct ThreadStats { | ^~~~~~~~~~~ In file included from /usr/include/c++/11/future:41, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/executors.hpp:18, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/rclcpp.hpp:155, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/../include/include/realtime_utils/realtime_utils.hpp:3, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_subscriber.cpp:1: /usr/include/c++/11/atomic:875:7: note: declared here 875 | atomic(const atomic&) = delete; | ^~~~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/c++allocator.h:33, from /usr/include/c++/11/bits/allocator.h:46, from /usr/include/c++/11/memory:64, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/rclcpp.hpp:153, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/../include/include/realtime_utils/realtime_utils.hpp:3, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_publisher.cpp:1: /usr/include/c++/11/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = MultiThreadPublisher::ThreadStats; _Args = {const MultiThreadPublisher::ThreadStats&}; _Tp = MultiThreadPublisher::ThreadStats]’: /usr/include/c++/11/bits/alloc_traits.h:516:17: required from ‘static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = MultiThreadPublisher::ThreadStats; _Args = {const MultiThreadPublisher::ThreadStats&}; _Tp = MultiThreadPublisher::ThreadStats; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<MultiThreadPublisher::ThreadStats>]’ /usr/include/c++/11/bits/stl_vector.h:1192:30: required from ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = MultiThreadPublisher::ThreadStats; _Alloc = std::allocator<MultiThreadPublisher::ThreadStats>; std::vector<_Tp, _Alloc>::value_type = MultiThreadPublisher::ThreadStats]’ /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_publisher.cpp:153:35: required from here /usr/include/c++/11/ext/new_allocator.h:162:11: error: use of deleted function ‘MultiThreadPublisher::ThreadStats::ThreadStats(const MultiThreadPublisher::ThreadStats&)’ 162 | { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_publisher.cpp:35:12: note: ‘MultiThreadPublisher::ThreadStats::ThreadStats(const MultiThreadPublisher::ThreadStats&)’ is implicitly deleted because the default definition would be ill-formed: 35 | struct ThreadStats { | ^~~~~~~~~~~ /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_publisher.cpp:35:12: error: use of deleted function ‘std::atomic<long unsigned int>::atomic(const std::atomic<long unsigned int>&)’ In file included from /usr/include/c++/11/future:41, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/executors.hpp:18, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/rclcpp.hpp:155, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/../include/include/realtime_utils/realtime_utils.hpp:3, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_publisher.cpp:1: /usr/include/c++/11/atomic:898:7: note: declared here 898 | atomic(const atomic&) = delete; | ^~~~~~ /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_publisher.cpp:35:12: error: use of deleted function ‘std::atomic<long unsigned int>::atomic(const std::atomic<long unsigned int>&)’ 35 | struct ThreadStats { | ^~~~~~~~~~~ In file included from /usr/include/c++/11/future:41, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/executors.hpp:18, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/rclcpp.hpp:155, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/../include/include/realtime_utils/realtime_utils.hpp:3, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_publisher.cpp:1: /usr/include/c++/11/atomic:898:7: note: declared here 898 | atomic(const atomic&) = delete; | ^~~~~~ /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_publisher.cpp:35:12: error: use of deleted function ‘std::atomic<long int>::atomic(const std::atomic<long int>&)’ 35 | struct ThreadStats { | ^~~~~~~~~~~ In file included from /usr/include/c++/11/future:41, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/executors.hpp:18, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/rclcpp.hpp:155, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/../include/include/realtime_utils/realtime_utils.hpp:3, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_publisher.cpp:1: /usr/include/c++/11/atomic:875:7: note: declared here 875 | atomic(const atomic&) = delete; | ^~~~~~ /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_publisher.cpp:35:12: error: use of deleted function ‘std::atomic<long int>::atomic(const std::atomic<long int>&)’ 35 | struct ThreadStats { | ^~~~~~~~~~~ In file included from /usr/include/c++/11/future:41, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/executors.hpp:18, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/rclcpp.hpp:155, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/../include/include/realtime_utils/realtime_utils.hpp:3, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_publisher.cpp:1: /usr/include/c++/11/atomic:875:7: note: declared here 875 | atomic(const atomic&) = delete; | ^~~~~~ In file included from /usr/include/c++/11/memory:66, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/rclcpp.hpp:153, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/../include/include/realtime_utils/realtime_utils.hpp:3, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_publisher.cpp:1: /usr/include/c++/11/bits/stl_uninitialized.h: In instantiation of ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<MultiThreadPublisher::ThreadStats*>; _ForwardIterator = MultiThreadPublisher::ThreadStats*]’: /usr/include/c++/11/bits/stl_uninitialized.h:333:37: required from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = std::move_iterator<MultiThreadPublisher::ThreadStats*>; _ForwardIterator = MultiThreadPublisher::ThreadStats*; _Tp = MultiThreadPublisher::ThreadStats]’ /usr/include/c++/11/bits/stl_uninitialized.h:355:2: required from ‘_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = MultiThreadPublisher::ThreadStats*; _ForwardIterator = MultiThreadPublisher::ThreadStats*; _Allocator = std::allocator<MultiThreadPublisher::ThreadStats>]’ /usr/include/c++/11/bits/vector.tcc:659:48: required from ‘void std::vector<_Tp, _Alloc>::_M_default_append(std::vector<_Tp, _Alloc>::size_type) [with _Tp = MultiThreadPublisher::ThreadStats; _Alloc = std::allocator<MultiThreadPublisher::ThreadStats>; std::vector<_Tp, _Alloc>::size_type = long unsigned int]’ /usr/include/c++/11/bits/stl_vector.h:940:4: required from ‘void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = MultiThreadPublisher::ThreadStats; _Alloc = std::allocator<MultiThreadPublisher::ThreadStats>; std::vector<_Tp, _Alloc>::size_type = long unsigned int]’ /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_publisher.cpp:60:29: required from here /usr/include/c++/11/bits/stl_uninitialized.h:138:72: error: static assertion failed: result type must be constructible from value type of input range 138 | static_assert(is_constructible<_ValueType2, decltype(*__first)>::value, | ^~~~~ /usr/include/c++/11/bits/stl_uninitialized.h:138:72: note: ‘std::integral_constant<bool, false>::value’ evaluates to false In file included from /usr/include/c++/11/memory:66, from /home/yidds/YiDDS/YiDDS_humble/install/rclcpp/include/rclcpp/rclcpp/rclcpp.hpp:153, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/../include/include/realtime_utils/realtime_utils.hpp:3, from /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_subscriber.cpp:1: /usr/include/c++/11/bits/stl_uninitialized.h: In instantiation of ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<MultiThreadSubscriber::ThreadStats*>; _ForwardIterator = MultiThreadSubscriber::ThreadStats*]’: /usr/include/c++/11/bits/stl_uninitialized.h:333:37: required from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = std::move_iterator<MultiThreadSubscriber::ThreadStats*>; _ForwardIterator = MultiThreadSubscriber::ThreadStats*; _Tp = MultiThreadSubscriber::ThreadStats]’ /usr/include/c++/11/bits/stl_uninitialized.h:355:2: required from ‘_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = MultiThreadSubscriber::ThreadStats*; _ForwardIterator = MultiThreadSubscriber::ThreadStats*; _Allocator = std::allocator<MultiThreadSubscriber::ThreadStats>]’ /usr/include/c++/11/bits/vector.tcc:659:48: required from ‘void std::vector<_Tp, _Alloc>::_M_default_append(std::vector<_Tp, _Alloc>::size_type) [with _Tp = MultiThreadSubscriber::ThreadStats; _Alloc = std::allocator<MultiThreadSubscriber::ThreadStats>; std::vector<_Tp, _Alloc>::size_type = long unsigned int]’ /usr/include/c++/11/bits/stl_vector.h:940:4: required from ‘void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = MultiThreadSubscriber::ThreadStats; _Alloc = std::allocator<MultiThreadSubscriber::ThreadStats>; std::vector<_Tp, _Alloc>::size_type = long unsigned int]’ /home/yidds/YiDDS/multithreading_YIDDS/src/realtime_demo/src/multithread_subscriber.cpp:67:29: required from here /usr/include/c++/11/bits/stl_uninitialized.h:138:72: error: static assertion failed: result type must be constructible from value type of input range 138 | static_assert(is_constructible<_ValueType2, decltype(*__first)>::value, | ^~~~~ /usr/include/c++/11/bits/stl_uninitialized.h:138:72: note: ‘std::integral_constant<bool, false>::value’ evaluates to false 修改完给我完整的代码,要求功能基本不变,
07-31
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Data-Mining

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值