C cannot find -lc_p

I'm following a book's (Wrox Press's Professional Assembly Language) explanation of how to profile code and I tried this incantation:

Code:
gcc12 -pg -o demo demo.c

but got this error:
Code:
/usr/local/bin/ld: cannot find -lc_p: No such file or directory
collect2: error: ld returned 1 exit status

I googled everywhere, but I can't figure it out. I'm guessint c_p is a profiling library. Where is it or where do I get it and how'd you know?

If you must have the c code:

Code:
#include <stdio.h>
void function1()
{
    int i, j;
    for(i=0; i <100000; i++)
        j += i;
}
void function2()
{
    int i, j;
    function1();
    for(i=0; i < 200000; i++)
        j = i;
}
int main()
{
    int i, j;
    for (i = 0; i <100; i++)
        function1();
    for(i = 0; i<50000; i++)
        function2();
    return 0;
 
BTW, I know it's gcc (I have gcc and binutils installed and it builds, runs, and debug's fine). The book doesn't cover clang, but I figure once I figure it out one way, I can switch over to the other. I'd hate to have to fire up linux, just to try out the stuff in the book, but if all else fails, I can...
 
And you might need -L to specify library path

 
I'm a little slow sometimes -

On the system:

man gprof

Code:
DESCRIPTION
       "gprof" produces an execution profile of C, Pascal, or Fortran77
       programs.  The effect of called routines is incorporated in the profile
       of each caller.  The profile data is taken from the call graph profile
       file (gmon.out default) which is created by programs that are compiled
       with the -pg option of "cc", "pc", and "f77".  The -pg option also
       links in versions of the library routines that are compiled for
       profiling.  "Gprof" reads the given object file (the default is
       "a.out") and establishes the relation between its symbol table and the
       call graph profile from gmon.out.  If more than one profile file is
       specified, the "gprof" output shows the sum of the profile information
       in the given profile files.

On the web https://man.freebsd.org/cgi/man.cgi?query=gprof&sektion=1:

Code:
DESCRIPTION
       The gprof utility produces an execution profile of C, Pascal,  or  For-
       tran77  programs.  The effect of    called routines    is incorporated    in the
       profile of each caller.    The profile data is taken from the call     graph
       profile    file  which  is    created    by programs that are compiled with the
       -pg option of cc(1), pc(1), and f77(1).    The -pg    option also  links  in
       versions     of  the library routines that are compiled for    profiling.  By
       convention these    libraries have their name suffixed with    _p, i.e.,  the
       profiled    version    of libc.a is libc_p.a and if you specify libraries di-
       rectly  to  the    compiler  or  linker you can use -lc_p instead of -lc.
       Read the    given object file (the default is a.out) and  establishes  the
       relation     between its symbol table and the call graph profile. ...

I wonder why they mucked with the manpage and took out the last bit about libc...

It looks like it is looking for a version of libc that's got profiling options. Well, I'm not keen on running a non-standard libc, or is this something I can build without installing and run it for a single process like my demo? Would I just build it as a port but not install it or what?
 
If you want to profile don't bother with gprof.

Go right to flame graphs via dtrace. And no special libc required:
 
Back
Top