[lttng-dev] Unable to use libbabeltrace for trace reading in C program

Alexis Martin alexis.martin at inria.fr
Wed Feb 24 03:50:41 EST 2016


Hi,

> On 24 Feb 2016, at 01:13, Julien Desfossez <jdesfossez at efficios.com> wrote:
> 
> Hi,
> 
>> Hi,
>> 
>> I’m trying to use the babeltrace library to be able to load and read a CTF trace in a C program.
>> 
>> From the doc:
>> 
>>> In order to use libbabeltrace to read a trace, the first step is to create a
>>> context structure and to add a trace to it. This is done using the
>>> bt_context_create() and bt_context_add_trace() functions. As long as this
>>> context structure is allocated and the trace is valid, the trace can be
>>> manipulated by the library.
>> 
>> 
>> But for a simple program like this:
>> 
>>> #include <stdio.h>
>>> #include <babeltrace/context.h>
>>> 
>>> int main(void){
>>> 
>>>    struct bt_context *ctx = bt_context_create();
>>> 
>>>    int ret = bt_context_add_trace(ctx, "/home/alex/trace/ffmpeg/kernel/", "ctf", NULL, NULL, NULL);
>>> 
>>>    return ret;
>>> 
>>> }
>> 
>> 
>> I got the following error message:
>> 
>>> [error] [Context] Format "ctf" unknown.
> 
> It sounds like a linking problem, try to compile with this, it should
> work:
> gcc -o a a.c -lbabeltrace -Wl,—no-as-needed -lbabeltrace-ctf
> 

It was indeed a linking problem, I was linking only with the libbabeltrace and not also with libbabeltrace-ctf…
Works perfectly now.

Thanks for helping

> I don't know if there is a cleaner solution, others will know.
> 
> Babeltrace discovers its supported formats with the libraries loaded
> when the program starts.
> 
> Julien


—
Alexis Martin
PhD. Student
INRIA / LIG POLARIS-Team
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lttng.org/pipermail/lttng-dev/attachments/20160224/59f2b72f/attachment-0001.html>


More information about the lttng-dev mailing list