[关闭]
@natsumi 2016-05-16T02:21:20.000000Z 字数 2317 阅读 3130

Ubuntu安装ZMQ

Ubuntu zmq socket


官网http://zeromq.org/下载

1. 安装

  1. configure: error: Package requirements (libsodium) were not met:
  2. No package 'libsodium' found
  3. Consider adjusting the PKG_CONFIG_PATH environment variable if you
  4. installed software in a non-standard prefix.
  5. Alternatively, you may set the environment variables sodium_CFLAGS
  6. and sodium_LIBS to avoid the need to call pkg-config.
  7. See the pkg-config man page for more details.

参考
https://github.com/zeromq/libzmq/issues/1274
http://blog.csdn.net/u011362822/article/details/42463695
http://www.itozi.net/19271.html
在configure时加上选项忽略掉这个包就行了
./configure --prefix=/home/libdev/zmq --without-libsodium

2. 测试使用zmq进行网络通信

http://www.cnblogs.com/fengbohello/p/4046686.html

zeroMQ编程实例
http://blog.csdn.net/chinabhlt/article/details/46873269

ZeroMQ(ZMQ)函数接口英汉直译
http://www.cnblogs.com/fengbohello/p/4230135.html

3. 运行时报错

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

通过find命令找这个网无法加载的库,在/usr/local/lib中可以找到。

  1. tiantian@tiantian-HP-EliteBook-2570p:~/value_Recv$ sudo find / -depth -name "libzmq.so.5" -print
  2. /usr/local/lib/libzmq.so.5
  3. /home/tiantian/zeromq-4.1.4/.libs/libzmq.so.5

参考这里的解决方法
http://stackoverflow.com/questions/17889799/libraries-in-usr-local-lib-not-found

这是运行时错误,不是编译错误。在编译时设置-L选项对运行时连接器没有意义。需要做的是,告诉runtime loader也去/usr/local/lib目录中找找所需的库。有三种方法(推荐2):

3.1 添加路径到LD_LIBRARY_PATH环境变量

$ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"

3.1 更新runtime linker的配置文件

/etc/ld.so.conf文件中加入/usr/local/lib
或者
/etc/ld.so.conf.d/目录下创建一个新的*.conf文件,里面写入这个路径/usr/local/lib
例如/etc/ld.so.conf.d/99local.conf
文件内容为/usr/local/lib

后者是推荐的方式,可以将自定义路径和系统路径分开,“99”可以确保这些路径中的库最后被加载,不会取代系统路径中的同名库。

修改完root执行ldconfig让修改生效(这个命令会更新/etc/ld.so.cache文件,这是runtime linker实际使用的文件)

3.3 用-rpath添加连接选项

There's also another way for a binary to find needed libraries at runtime. You can actually hard-code library paths into the executable itself. This is accomplished by setting a so called "rpath". This is a linker option and must be passed from gcc (or g++) to the linker, so the -Wl option has to be used. The linker option is -rpath=PATH. So you would need to add this to your link flags:

-Wl,-rpath=/usr/local/lib

I don't recommend this for your case though. An rpath is useful when you're shipping libraries together with your executable (maybe with an installer), and a relative rpath (using the rpath $ORIGIN feature) or absolute one (for when you install in /opt, for example) is then used to find those bundled libs at runtime.

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注