Feature #338
closedTrace probe can not be compiled with g++
100%
Description
I'd like to use LTTng in the context of C++ projects. The trace probe itself is always a "C" file, in the examples called tp.c.
If I use a C++ file instead, e.g. by renaming the tp.c to tp.cpp, the compilation fails, since the two enumerations alloc and sync are defined within the scope of the lttng_ust_lib_ring_buffer_config structure and thus their literals are not found (there are additional problems, if I try to define these two enumerations on top level).
Using a C file instead of a C++ is sometimes a bit problematic. In my case, I am integrating LTTng into the Papyrus code generation and I do not like mixing the C and C++ code generation (although possible).
Files
Updated by Zifei Tong over 11 years ago
- File 0001-Fix-make-hello.cxx-compile-with-g.patch 0001-Fix-make-hello.cxx-compile-with-g.patch added
I did some research on this today, and finally made g++ compile 'hello.cxx' example.
The main problem is designated initializer. G++ do support designated initializer, however only 'trivial designated initializers' are supported, otherwise it will complain: 'sorry, unimplemented: non-trivial designated initializers not supported'.
After some trial-and-error, it seems that 'trivial designated initializers' means no out-of-order initialization and no missing initialization (except the fields on the tail of a struct).
And nested initialization should be done in the form {.foo = {.bar = 1}} instead of {.foo.bar = 1}.
So I reordered some initializers, add some fields, and change nested initializations in the above odd form to make g++ happy.
Updated by Zifei Tong over 11 years ago
- Status changed from New to Resolved
- % Done changed from 0 to 100
Applied in changeset 46d522007b647e0b64d18d0ed518205c2bbad424.