歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> RabbitMQ客戶端C++安裝詳細記錄

RabbitMQ客戶端C++安裝詳細記錄

日期:2017/2/28 15:57:25   编辑:Linux教程

c客戶端環境安裝
1. 下載 rabbitmq-c 源碼包 http://hg.rabbitmq.com/rabbitmq-c/
2. 下載 rabbitmq-codegen 源碼包 http://hg.rabbitmq.com/rabbitmq-codegen/
3. 將rabbitmq-codegen拷貝到rabbitmq-c的目錄下,改名為codegen
4. macro `AM_PROG_LIBTOOL’ not found in library 解決方案
產生這個報錯的原因有兩種,一種是沒有安裝libtool,一種是安裝了libtool但是aclocal和libtool未安裝在同一文件夾下。
5. 執行 autoreconf -i
6. 安裝python的json包或simplejson包
7. 修改configure文件,屏蔽python檢查部分,大約在20174-20198行。裡面有語法錯誤。這個主要是檢查第三步的那兩個python包有沒有安裝,如下注釋掉即可。

[python]
  1. #checkPython python
  2. #checkPython python2.6
  3. #checkPython python2.5
  4. #if test "$found_python" = "no"
  5. #then
  6. # { { echo "$as_me:$LINENO: error: could not find a python that can 'import simplejson'" >&5
  7. #echo "$as_me: error: could not find a python that can 'import simplejson'" >&2;}
  8. # { (exit 1); exit 1; }; }
  9. #fi

8. 執行./configure

有的電腦會出現如下錯誤:

[html]
  1. Cannot find install-sh, install.sh, or shtool in ac-aux

解決方法:

[python]
  1. $ libtoolize --force
  2. $ aclocal
  3. $ autoheader
  4. $ automake --force-missing --add-missing
  5. $ autoconf
  6. $ ./configure
9. 進入librabbitmq目錄,修改Makefile, www.linuxidc.com 將PYTHON變量的內容改成自己用的版本,原來的是空,大約在150行

[html]
  1. PYTHON = python2.6

10. make, make check, make install

11.安裝成功後,查看readme裡面的內容,有可執行的例子:

[python]
  1. ./examples/amqp_listen localhost 5672 amq.direct test

amqp_listen為監聽程序

localhost : rabbitmq服務host 5672 : 服務開放端口

[python]

  1. ./examples/amqp_sendstring localhost 5672 amq.direct test "hello world"

amqp_sendstring為發送程序

c++客戶端
1. 必須先安裝c客戶端環境
2. 下載源碼包 https://github.com/akalend/amqpcpp
3. 按README執行即可
4. 原版本編譯後是.a文件,如果要改成.so文件需要自己修改makefile,步驟如下
a. 修改CFLAGS變量, 增加-fPIC -shared參數
b.LIBFILE = lib$(LIBNAME).so
c. 修改$(LIBFILE)的編譯語句, 屏蔽原來的 $(AR) 命令, 改成 $(CXX) $(CPPFLAGS) -o $@ $(OBJECTS)

[python]
  1. $(LIBFILE): $(OBJECTS)
  2. # $(AR) rcs $@ $(OBJECTS)
  3. $(CXX) $(CPPFLAGS) -o $@ $(OBJECTS)

5.make
6.copy the libamqpcpp.a to /usr/local/lib or other system library dir.
copy the libamqpcpp.so to /usr/local/lib or other system library dir.
7.export LD_LIBRARY_PATH=":/usr/local/lib"

Copyright © Linux教程網 All Rights Reserved