Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#ifdef __cplusplus missing in tracking_cpu_stats.h #23072

Closed
ghost opened this issue Feb 25, 2020 · 1 comment · Fixed by #23077
Closed

#ifdef __cplusplus missing in tracking_cpu_stats.h #23072

ghost opened this issue Feb 25, 2020 · 1 comment · Fixed by #23077
Labels
bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@ghost
Copy link

ghost commented Feb 25, 2020

Describe the bug
When we include the header file subsys/tracing/include/tracing_cpu_stats.h
into the C++ file with reference to one of the functions it will not link.

To Reproduce
Steps to reproduce the behavior:

  1. add C++ file into the Zephyr project
  2. enable TRACING_CPU_STATS in menuconfig
  3. #include "tracing_cpu_stats.h"
  4. call on of the functions, e.g. cpu_stats_non_idle_and_sched_get_percent();
  5. compile and see the error

Expected behavior
The project should compile and link.

Impact
The feature prevent from compiling the project.

Screenshots or console output
: app/libapp.a(cpu_detailed_stats.cpp.obj): in function saveData': /home/hid/aurora/aurora/app/src/cpu_stats/cpu_detailed_stats.cpp:169: undefined reference to cpu_stats_non_idle_and_sched_get_percent()'
/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: /home/hid/aurora/aurora/app/src/cpu_stats/cpu_detailed_stats.cpp:171: undefined reference to `cpu_stats_reset_counters()'
collect2: error: ld returned 1 exit status

Environment (please complete the following information):

  • OS: Linux
  • Toolchain ninja
  • Version 2.2.0.0

Additional context
The fix is to add the following #ifdefs into the header file:

diff --git a/subsys/tracing/include/tracing_cpu_stats.h b/subsys/tracing/include/tracing_cpu_stats.h
index cacaad21e0..4c5c2d23a9 100644
--- a/subsys/tracing/include/tracing_cpu_stats.h
+++ b/subsys/tracing/include/tracing_cpu_stats.h
@@ -10,6 +10,10 @@
#include <kernel_structs.h>
#include <init.h>

+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct cpu_stats {
u64_t idle;
u64_t non_idle;
@@ -41,4 +45,8 @@ void cpu_stats_reset_counters(void);
#define sys_trace_void(id)
#define sys_trace_end_call(id)

+#ifdef __cplusplus
+}
+#endif
+
#endif /* _TRACE_CPU_STATS_H */

@ghost ghost added the bug The issue is a bug, or the PR is fixing a bug label Feb 25, 2020
@ioannisg
Copy link
Member

thanks for this bug report -
would it be possible to provide a fix PR @dlisik-hid ?

@jhedberg jhedberg assigned ghost Feb 25, 2020
@jhedberg jhedberg added the priority: low Low impact/importance bug label Feb 25, 2020
jhedberg pushed a commit that referenced this issue Feb 26, 2020
When tracing_cpu_stats.h is included by C++ file it will not compile
and link correctly due to missing #ifdef __cplusplus directives
in the header file.

Fixes #23072

Signed-off-by: Dariusz Lisik <dariusz.lisik@hidglobal.com>
hakehuang pushed a commit to hakehuang/zephyr that referenced this issue Mar 18, 2020
When tracing_cpu_stats.h is included by C++ file it will not compile
and link correctly due to missing #ifdef __cplusplus directives
in the header file.

Fixes zephyrproject-rtos#23072

Signed-off-by: Dariusz Lisik <dariusz.lisik@hidglobal.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants