0

I want to use libpfm4 library for Perf_Event but compiling program which have library function throws following error.

   /tmp/ccYD603t.o: In function `main':
    encod.c:(.text+0x44): undefined reference to `pfm_initialize'
    encod.c:(.text+0x57): undefined reference to `pfm_strerror'
    encod.c:(.text+0x97): undefined reference to `pfm_get_perf_event_encoding'
    encod.c:(.text+0xaa): undefined reference to `pfm_strerror'

collect2: ld returned 1 exit status

please can any one tell me how configure library in system to resolve this error.

  • That is a linker failure. Libraries at end (http://stackoverflow.com/questions/9923495/undefined-reference-shm-open-already-add-lrt-flag-here). – hmjd Dec 08 '14 at 13:08
  • 2
    Show how you're compiling. – Praxeolitic Dec 08 '14 at 13:13
  • Please provide all relevant information to reproduce your problem. Right now, we don't know a) what code you compile and b) how you invoke the compiler. Both pieces of information are needed to answer your question. – fuz Dec 08 '14 at 14:57

1 Answers1

2

As noted in the comments, you're looking at a linker error. Because this is a common error we have a reference question for this:

What is an undefined reference/unresolved external symbol error and how do I fix it?

To tell you more about exactly what you're doing wrong we'll need to see how you're compiling. Briefly, you're likely #includeing library headers but not linking the library. The compiler is telling the linker that the compiled code will need entities declared in the library headers but then the linker chokes because it doesn't know the definitions of those entities.

Community
  • 1
  • 1
Praxeolitic
  • 22,455
  • 16
  • 75
  • 126