[lttng-dev] use of extern before tracepoint definition

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Mon Oct 7 12:12:29 EDT 2019



----- On Oct 7, 2019, at 12:06 PM, Yonghong Yan yanyh15 at gmail.com wrote:

> I am not sure whether this is a bug or the wrong I am using it. When I use
> extern declaration as follows, I always have compilation error. I used the
> easy-ust to demonstrate:

> diff --git a/doc/examples/easy-ust/sample_component_provider.h
> b/doc/examples/easy-ust/sample_component_provider.h

> index dd3c5f0..e70d650 100644

> --- a/doc/examples/easy-ust/sample_component_provider.h

> +++ b/doc/examples/easy-ust/sample_component_provider.h

> @@ -61,6 +61,8 @@

> */

> #include <lttng/tracepoint.h>

> +extern int testint(int i);

The tracepoint provider header is included within the lttng-ust tracepoint
header generation in multiple passes. Therefore, you should not add "any"
code in this header. Else you need to guard it with precompiler conditionals
to ensure it is only emitted the first time the header is included, and not
the following times.

e.g.

#ifndef SAMPLE_COMPONENT_PROVIDER_ONCE
#define SAMPLE_COMPONENT_PROVIDER_ONCE

extern int testint(int i);

#endif

Thanks,

Mathieu



> +

> /*

> * The following tracepoint event writes a message (c string) into the

> * field message of the trace event message in the provider

> yanyh at vm : ~/tools/lttng/lttng-ust/doc/examples/easy-ust $ make

> cc -I. \

> -save-temps -c -o sample.o sample.c

> cc -I. \

> -save-temps -c -o tp.o tp.c

> In file included from /usr/include/lttng/ust-tracepoint-event.h:974:0 ,

> from /usr/include/lttng/tracepoint-event.h:58 ,

> from sample_component_provider.h:137 ,

> from tp.c:33 :

> ././sample_component_provider.h:64:1: error: expected expression before ‘ extern
>
> extern int testint(int i);

> ^

> Makefile:34: recipe for target 'tp.o' failed

> make: *** [tp.o] Error 1

> Thank you

> Yonghong

> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com


More information about the lttng-dev mailing list