linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Joel Fernandes (Google)" <joel@joelfernandes.org>
To: linux-trace-devel@vger.kernel.org
Cc: rostedt@goodmis.org, "Joel Fernandes (Google)" <joel@joelfernandes.org>
Subject: [PATCH 1/2] trace-cmd: libtracecmd: Fixing linking to C++ code
Date: Sun, 14 Aug 2022 23:13:41 -0400	[thread overview]
Message-ID: <20220815031342.775201-1-joel@joelfernandes.org> (raw)

Linking in C++ compilers (including g++) causes references to be created
with their arguments. Due to this, trace library headers included into
C++ code base will cause their objects to built with symbols with
arguments. Apparently this is to support operator overloading in C++.

This causes linker errors. For example, here's what I get when I try to
link libtracecmd with a main.o built from a C++ main.cc source file.

 main.cc:(.text+0x90):
	undefined reference to `tracecmd_get_tep(tracecmd_input*)'
	undefined reference to `tracecmd_free_record(tep_record*)'
	undefined reference to `tracecmd_read_data(tracecmd_input*, int)'

The standard fix for this is to wrap the C project's header in
extern "C".

With this patch, I am able to link libtracecmd into a C++
code base.

Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
 include/trace-cmd/trace-cmd.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h
index 4963f45..b050233 100644
--- a/include/trace-cmd/trace-cmd.h
+++ b/include/trace-cmd/trace-cmd.h
@@ -9,6 +9,10 @@
 #include "event-parse.h"
 #include "tracefs.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct tracecmd_input;
 
 enum tracecmd_open_flags {
@@ -78,5 +82,8 @@ struct tracecmd_filter *tracecmd_filter_add(struct tracecmd_input *handle,
 					    const char *filter_str, bool neg);
 enum tracecmd_filters tracecmd_filter_match(struct tracecmd_filter *filter,
 					    struct tep_record *record);
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* _TRACE_CMD_H */
-- 
2.25.1


             reply	other threads:[~2022-08-15  3:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-15  3:13 Joel Fernandes (Google) [this message]
2022-08-15  3:13 ` [PATCH 2/2] trace-cmd: README: Add note on installing libtracecmd Joel Fernandes (Google)
2022-09-22  1:43   ` Steven Rostedt
2022-09-22  2:56     ` Joel Fernandes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220815031342.775201-1-joel@joelfernandes.org \
    --to=joel@joelfernandes.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).