使用g++编译、运行libuv的demo错误解决

我们通过例子来讲述监视器的使用. 例子中空转监视器回调函数被不断地重复调用,  通过例子我们也可以了解到:

由于设置了监视器, 所以调用 uv_run() 是程序会阻塞, 空转监视器将会在计数器达到设定的值时停止(监视), uv_run() 会退出因为此时程序中没有活动的监视器了.

测试代码如下

 #include <stdio.h>
#include <uv.h> int64_t counter = ; static void wait_for_a_while(uv_idle_t* handle) {
counter++; if (counter >= 10e6)
uv_idle_stop(handle);
} int main() {
uv_idle_t idler;
uv_idle_init(uv_default_loop(), &idler);
uv_idle_start(&idler, wait_for_a_while); printf("Idling...\n");
uv_run(uv_default_loop(), UV_RUN_DEFAULT); return ;
}

g++ -c libuv_test.c  //生成libuv_test.o文件

g++ -o libuvtest libuv_test.o  /usr/local/bin/libuv.so  生成目标文件要包含libuv.so库,这里需要全路径,因为我们用到了它里面的函数。

chmod 755 libtest  //赋予执行权限

./libtest

报错libtest: error while loading shared libraries: libuv.so.1: cannot open shared object file: No such file or directory

分析原因:ld提示找不到库文件,而库文件就在/usr/local/lib目录中。

链接器ld默认的目录是/lib和/usr/lib,如果放在其他路径也可以,需要让ld知道库文件在哪里。

方法1:

编辑/etc/ld.so.conf文件,在新的一行中加入库文件所在目录;

运行ldconfig,以更新/etc/ld.so.cache文件;

方法2:

在/etc/ld.so.conf.d/目录下新建任何以.conf为后缀的文件,在该文件中加入库文件所在的目录;

运行ldconfig,以更新/etc/ld.so.cache文件;

 我的解决办法是:在./etc/ld.so.conf文件中添加了/usr/local/lib/ 

本人觉得第二种办法更为方便,对于原系统的改动最小。因为/etc/ld.so.conf文件的内容是include /etc/ld.so.conf.d/*.conf

所以,在/etc/ld.so.conf.d/目录下加入的任何以.conf为后缀的文件都能被识别到

ld.so.cache的更新是递增式的,就像PATH系统环境变量一样,不是从头重新建立,而是向上累加。

除非重新开机,才是从零开始建立ld.so.cache文件。

报错libtest: error while loading shared libraries: libuv.so.1: cannot open shared object file: No such file or directory的更多相关文章

  1. 运行 puppeteer 报错 chrome: error while loading shared libraries: libpangocairo-1.0.so.0: cannot open shared object file: No such file or directory

    运行 puppeteer 报错 chrome: error while loading shared libraries: libpangocairo-1.0.so.0: cannot open sh ...

  2. linux下报错:error while loading shared libraries

    linux执行bin程序报: error while loading shared libraries:libncurses.so.5: cannot open shared object file: ...

  3. 解决ffmpeg执行报错“ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No such file or directory”的问题

    问题现象: 执行ffmpeg命令后报错: ffmpeg: error : cannot open shared object file: No such file or directory 出问题的环 ...

  4. java 罕见的依赖报错 jstat: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory

    java 都用了N长时间了,突然,意外地发现有一个依赖的so文件从来没找见过 # ldd /usr/bin/java linux-vdso.so.1 =>  (0x00007fffba76900 ...

  5. imod报错:error while loading shared libraries: libjpeg.so.62的解决办法

    the file libjpeg.so.62(in /usr/lib/libjpeg.so.62)belongs to the package libjpeg62so try to reinstall ...

  6. nginx排错error while loading shared libraries:libpcre.so.1:cannot open shared object file:No such file or directory

    启动nginx报错:error while loading shared libraries:libpcre.so.1:cannot open shared object file:No such f ...

  7. 使用arm-none-eabi-gdb报错error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

    使用arm-none-eabi-gdb报错error while loading shared libraries: libncurses.so.5: cannot open shared objec ...

  8. 报错:/application/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory

    启动zabbix_server时报错: /application/zabbix/sbin/zabbix_server: error while loading shared libraries: li ...

  9. nginx检查报错 error while loading shared libraries: libprofiler.so.0: cannot open shared object file: No such file or directory

    在centos7.3上编译安装nginx-1.12.2 启动测试出错 [root@web02 local]# /usr/local/nginx/sbin/nginx -t /usr/local/ngi ...

随机推荐

  1. javascript 原生常用api 数组方法大全

     <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. cocos2dx之保存截屏图片

    http://blog.csdn.net/ganpengjin1/article/details/19088921 我们要保存当前的运行的scene的截图的话,我用到CCRenderTexture,看 ...

  3. Android四大组件应用系列——使用BroadcastReceiver和Service实现倒计时

    一.问题描述 Service组件可以实现在后台执行一些耗时任务,甚至可以在程序退出的情况下,让Service在后台继续保持运行状态.Service分本地服务和远程服务,Local地服务附在主进程上的m ...

  4. OpenCV3 for python3 学习笔记2

    1.安装 如果你是第一次使用OpenCV Python开发包,想要安装OpenCV Python只要执行如下命令行即可:  pip install opencv-python   如果你还想使用Ope ...

  5. MySQL(3)-MySQL Workbench

    远程连接mysql不上,CentOS7下的防火墙关闭命令,别光看iptables的状态. # systemctl stop firewalld # systemctl mask firewalld   ...

  6. 转发:查看centos中的用户和用户组

    1.用户列表文件:/etc/passwd/ 2.用户组列表文件:/etc/group 3.查看系统中有哪些用户: cut -d : -f 1 /etc/passwd 4.查看可以登录系统的用户: ca ...

  7. mysql函数和操作符

    mysql,); //取模函数 +-----------+ ,) | +-----------+ | +-----------+ row in set (0.00 sec) mysql,); +--- ...

  8. 利用useragent判断移动设备

    用 User Agent 判断移动设备 WebApp除了做成响应式设计以外,还可以给移动设备做一套UI,PC端再做一套UI,然后在前台进行判断进行相应的跳转.判断是否是移动设备一般根据浏览器的user ...

  9. CentOS 7 安装SVN并整合HTTP访问

    #!/bin/bash## -------------------------------------------------## 安装svn并整合http访问## ----------------- ...

  10. 【读书笔记】Data_Mining_with_R---Chapter_2_Predicting Algae Blooms

    本书概要 <Data Mining with R>这本书通过实例,并结合R讲解数据挖掘技术.本书的核心理念就是"Learning it by doing".本书分5章, ...