Problem with librt.a - correction

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with librt.a - correction

Guilherme Vilela
Hi,
I'm making a simple program to calculate the cpu execution time of a
process. I'm using the function clock_gettime like the line below:
...
if (clock_gettime (CLOCK_PROCESS_CPUTIME_ID,  &gtt_wall) != 0)
...
The problem only occur with the clock_id CLOCK_PROCESS_CPUTIME_ID. I'm
using CentOS 4.2.

When I compile my program with gcc using dynamic libraries (gcc -o
test test.c -ltr) the function clock_gettime return 0 ("success"), but
when I compile the program using static libraries (gcc -o test test.c
-static -ltr) the function clock_gettime returns -1 ("Invalid
argument").

Anybody knows why using librt.so the probram works but using librt.a
the program crashes?

Thanks,
Guilherme
Reply | Threaded
Open this post in threaded view
|

Re: Problem with librt.a - correction

Daniel Jacobowitz-2
On Thu, Oct 25, 2007 at 03:23:14PM -0200, Guilherme Vilela wrote:
> When I compile my program with gcc using dynamic libraries (gcc -o
> test test.c -ltr) the function clock_gettime return 0 ("success"), but
> when I compile the program using static libraries (gcc -o test test.c
> -static -ltr) the function clock_gettime returns -1 ("Invalid
> argument").
>
> Anybody knows why using librt.so the probram works but using librt.a
> the program crashes?

Don't use static linking.  This is one of many glibc problems that
lurk there.

If you must use static linking, try adding -lpthread explicitly.

--
Daniel Jacobowitz
CodeSourcery
Reply | Threaded
Open this post in threaded view
|

Re: Problem with librt.a - correction

Guilherme Vilela
Hi Daniel,
Yes, I must use static linking. I try your sugestion but I'm still
getting Invalid argument.

Thanks,
Guilherme

On 10/25/07, Daniel Jacobowitz <[hidden email]> wrote:

> On Thu, Oct 25, 2007 at 03:23:14PM -0200, Guilherme Vilela wrote:
> > When I compile my program with gcc using dynamic libraries (gcc -o
> > test test.c -ltr) the function clock_gettime return 0 ("success"), but
> > when I compile the program using static libraries (gcc -o test test.c
> > -static -ltr) the function clock_gettime returns -1 ("Invalid
> > argument").
> >
> > Anybody knows why using librt.so the probram works but using librt.a
> > the program crashes?
>
> Don't use static linking.  This is one of many glibc problems that
> lurk there.
>
> If you must use static linking, try adding -lpthread explicitly.
>
> --
> Daniel Jacobowitz
> CodeSourcery
>
Reply | Threaded
Open this post in threaded view
|

Re: Problem with librt.a - correction

Steve Munroe
In reply to this post by Guilherme Vilela
"Guilherme Vilela" <[hidden email]> wrote on 10/25/2007 12:23:14 PM:

> Hi,
> I'm making a simple program to calculate the cpu execution time of a
> process. I'm using the function clock_gettime like the line below:
> ...
> if (clock_gettime (CLOCK_PROCESS_CPUTIME_ID,  &gtt_wall) != 0)
> ...
> The problem only occur with the clock_id CLOCK_PROCESS_CPUTIME_ID. I'm
> using CentOS 4.2.
>
> When I compile my program with gcc using dynamic libraries (gcc -o
> test test.c -ltr) the function clock_gettime return 0 ("success"), but
> when I compile the program using static libraries (gcc -o test test.c
> -static -ltr) the function clock_gettime returns -1 ("Invalid
> argument").
>
> Anybody knows why using librt.so the probram works but using librt.a
> the program crashes?
>

Which GLIBC version and hardware?

Steven J. Munroe
Linux on Power Toolchain Architect
IBM Corporation, Linux Technology Center