[lttng-dev] linking c++ with shared object tracepoints

Jérémie Galarneau jeremie.galarneau at efficios.com
Tue Jun 4 11:09:43 EDT 2013


On Sun, Jun 2, 2013 at 3:47 AM, Aryeh Weinreb <weinrea at gmail.com> wrote:
>>> Is supported to link c++ code with c compiled tracepoints put it a dynamic lib?
>
> I mean to say the tracepoints put _in_ a dynamic lib before linking
> with c++ code.
>>
>> Yes, I just tried it here.
>
> Could you show me how with the easy-ust example?

I prepared a quick and dirty example based on the "demo" project.
Replace the Makefile and demo.c files with these:
https://gist.github.com/jgalar/5706595

This will compile a C++ application which links against the
lttng-ust-provider-ust-tests-demo3.so provider.

Resulting trace:
[10:59:42.399354875] (+?.?????????) mercury:demo:16256
ust_tests_demo3:done: { cpu_id = 4 }, { value = 42 }

Regards,
Jérémie

>
>> The header is probably fine and I'd advise againt modifying it without
>> careful thought. Could you provide a short example reproducing the
>> problem?
>
> $cd doc/examples/easy-ust/
> $ g++ -DTRACEPOINT_PROBE_DYNAMIC_LINKAGE  -I. -c -o sample.o sample.c
> sample.c: In function 'int main(int, char**)':
> sample.c:38: warning: deprecated conversion from string constant to 'char*'
> $ gcc -fPIC -I. -c -o tp.o tp.c
> $ gcc -I. -shared -o libtp.so tp.o
> $ g++ -o sample sample.o -ldl -llttng-ust -L. -ltp
> /usr/bin/ld: sample: hidden symbol `tracepoint_dlopen' in sample.o is
> referenced by DSO
> /usr/bin/ld: final link failed: Nonrepresentable section on output
> collect2: ld returned 1 exit status



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com



More information about the lttng-dev mailing list