使用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. html5调用手机陀螺仪实现方向辨识

    获取移动设备的陀螺仪,需要知道陀螺仪包含什么. 我们可以让document监听deviceorientation 来获取相关的数据,里面包括3个值 alpha.beta和gamma. 这三个值分别代表 ...

  2. Java+大数据开发——Hadoop集群环境搭建(一)

    1集群简介 HADOOP集群具体来说包含两个集群:HDFS集群和YARN集群,两者逻辑上分离,但物理上常在一起 HDFS集群: 负责海量数据的存储,集群中的角色主要有 NameNode / DataN ...

  3. [Python设计模式] 第10章 怎么出试卷?——模版方法模式

    github地址:https://github.com/cheesezh/python_design_patterns 题目 小时候数学老师的随堂测验,都是老师在黑板上写题目,学生在下边抄,然后再做题 ...

  4. Java中多环境Logback配置与ELK日志发送

    Java中多环境Logback配置与ELK日志发送   一.项目基于SpringBoot实现,引入SpringBoot相关库后,本文还要讲上传到ELK的Logstash,所以需要在pom.xml中加入 ...

  5. 国内混合APP开发技术选型

    http://www.sunzhongwei.com/weex-react-native-ionic-technology-selection 选谁? 企业级应用是要考虑性能和流畅度的, 如果只是做个 ...

  6. python dash 初探 --- k 线国内版

    python dash 的应用首页,是用一个 k 线图来做 damo 的,奈何数据源用的 Google,上不去.当然,可以换 yahoo,但是毕竟国内的还是更亲切些. 官方的 demo 用的 pand ...

  7. JAVA四则运算字符串解释器

    最近学习到后缀表达式,于是基于后缀表达式的思想,写了一个四则运算解释器,输入字符串类型的四则运算表达式,可以直接得到结果,支持括号嵌套. 实现时主要考虑以下两点: 字符串中运算符和数字分离 运算符优先 ...

  8. how to check the computer is 32 bit or 64bit in linux

    just use cat /proc/cpuinfo in shell

  9. Cannot attach the file as database

    Cannot attach the file as database这个异常是在EF的code frist里经常出现的,解决方法很简单,只要重新启动一下V11实例即可. CMD> sqlloca ...

  10. 转: 如何使用jstack分析线程状态

    这个讲的好系列:  如何使用jstack分析线程状态 转:http://www.jianshu.com/p/6690f7e92f27 背景 记得前段时间,同事说他们测试环境的服务器cpu使用率一直处于 ...