在 Linux 環境中安裝 RabbitMQ 的 C 與 C++ 客戶端,通常需要先處理相依套件、編譯工具與 Python 檢查問題。以下整理常見流程,方便後續編譯與測試。
首先下載 rabbitmq-c 與 rabbitmq-codegen 原始碼,並把 codegen 放到 rabbitmq-c 目錄下。接著安裝 libtool、autoconf、automake 等工具,再執行:
autoreconf -i ./configure make make check make install
若 configure 出現 Python 相關錯誤,可先安裝 python 的 json 或 simplejson 套件,或暫時註解掉相關檢查。若出現 install-sh 缺失,可嘗試重新產生建置檔:
libtoolize --force aclocal autoheader automake --force-missing --add-missing autoconf ./configure
安裝完成後,可執行範例程式測試 RabbitMQ 服務:
./examples/amqp_listen localhost 5672 amq.direct test ./examples/amqp_sendstring localhost 5672 amq.direct test "hello world"
C++ 客戶端需先完成 C 客戶端環境,再下載 amqpcpp 原始碼。依 README 執行 make 即可。若需要產生動態函式庫,可修改 Makefile,加入 -fPIC 與 -shared,並把靜態庫改名為 .so。完成後,將函式庫複製到系統目錄,並設定 LD_LIBRARY_PATH。