Not able to run PAPI code with papi.h, error : cannot open shared object file in GCC

Not able to run PAPI code with papi.h, error : cannot open shared object file in GCC

我正在尝试学习 papi api 来监控各种 CPU 事件的性能。首先,我 运行 PAPI 官方文档提到的示例片段之一。下面是代码

#include<stdio.h>
#include <unistd.h>
#include "papi.h"

#define NUM_EVENTS 2
int main()
{
int Events[NUM_EVENTS] = {PAPI_TOT_INS, PAPI_TOT_CYC};
int num1=1234;
int num2=9876;
int res1,res2;
long_long values[NUM_EVENTS];
/* Start counting events */
if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK)
    printf("\nerror!!!\n");
    //handle_error(1);
/* Do some computation here*/

res1=num1*num2;
printf("\n%d",res1);
/* Read the counters */
if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK)
    printf("\nerror!!!\n");
/* Do some computation here */

res2=num1+num2;
printf("\n%d",res2);
/* Stop counting events */
if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK)
    printf("\nerror!!!\n");
 return 0;
}

我用下面的包含文件路径编译它

gcc -I/home/sabarna/Desktop/DEV/clockCycle/papi/src/ papi_try1.c -L/home/sabarna/Desktop/DEV/clockCycle/papi/src/ -lpapi

执行 a.out 时出现错误

/a.out: error while loading shared libraries: libpapi.so.5: cannot open shared object file: No such file or directory

我尝试通过导出 LD_PRELOAD 来修复此问题,但没有成功。谁能帮帮我?我以前从未使用过 PAPI api,所以我不确定我是否以正确的方式编译它。

没有理由预加载那个库,尝试 defining/modifying LD_LIBRARY_PATH 而不是 LD_PRELOAD


-L/home/sabarna/Desktop/DEV/clockCycle/papi/src/ 好像编译了没安装

如果您将 LD_xxx 设置为 /home/sabarna/Desktop/DEV/clockCycle/papi/src/,这意味着库必须在目录 /home/sabarna/Desktop/DEV/clockCycle/papi/src/ 中而不是其他地方,所以 /home/sabarna/Desktop/DEV/clockCycle/papi/src/libpapy.so and/or /home/sabarna/Desktop/DEV/clockCycle/papi/src/libpapy.so.<number>存在