在Windows上将ActiveMQ-CPP编译为DLL

    ActiveMQ-CPP是ActiveMQ的C++客户端,因为官方未提供二进制文件,所以使用前需要先把源代码编译为动态库DLL或者静态库LIB文件。本文简单介绍生成DLL文件的步骤。编译前,需要先编译APR和CPPUNIT,生成对应的DLL和LIB文件。这2个组件的编译过程请参考本人或者其他网友的相关博文。

    ActiveMQ-CPP的下载地址为http://activemq.apache.org/cms/download.html,目前最新版本为3.8.2,对应的Windows源代码文件名为activemq-cpp-library-3.8.2-src.zip。将此文件下载到目录D:\Apache下,并解压,然后将子目录改名为activemq-cpp。

    建立目录D:\Apache\lib,将APR和CPPUNIT的LIB文件拷贝到此目录下。

    用Visual C++ 2010或更高版本的VC打开文件:D:\Apache\activemq-cpp\vs2008-build\activemq-cpp.sln,将工程activemq-cpp设置为Win32 ReleaseDLL模式、工程activemq-cpp-example设置为Win32 Release模式,编辑这2个工程的属性:添加头文件搜索目录:D:\Apache\cppunit\include、D:\Apache\arp\include、D:\Apache\apr-iconv\include、D:\Apache\apr-util\include;并添加库搜索目录:D:\Apache\lib。然后编译这2个工程, 编译后生成文件D:\Apache\activemq-cpp\vs2008-build\Win32\ReleaseDLL\activemq-cpp.dll,D:\Apache\activemq-cpp\vs2008-build\Release\activemq-cpp-example.exe。

    编译时会出现很多次C4819警告:

1>D:\Apache\activemq-cpp\src\main\decaf/util/Date.h : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss

解决办法:打开date.h文件;点击菜单File->Advanced Save Options,在弹出的选项中选择新的编码方式为:UNICODE codepage 1200,点击确定;保存date.h文件重新编译。


    activemq-cpp-example.exe可以用来测试activemq-cpp.dll。启动ActiveMQ后,执行activemq-cpp-example.exe,部分输出结果如下:

Message #1974 Received: Hello world! from thread 25808
Sent message #1991 from thread 25808
Message #1975 Received: Hello world! from thread 25808
Sent message #1992 from thread 25808
Message #1976 Received: Hello world! from thread 25808
Sent message #1993 from thread 25808
Message #1977 Received: Hello world! from thread 25808
Sent message #1994 from thread 25808
Sent message #1995 from thread 25808
Message #1978 Received: Hello world! from thread 25808
Sent message #1996 from thread 25808
Message #1979 Received: Hello world! from thread 25808
Sent message #1997 from thread 25808
Message #1980 Received: Hello world! from thread 25808
Sent message #1998 from thread 25808
Message #1981 Received: Hello world! from thread 25808
Sent message #1999 from thread 25808
Message #1982 Received: Hello world! from thread 25808
Sent message #2000 from thread 25808
Message #1983 Received: Hello world! from thread 25808
Message #1984 Received: Hello world! from thread 25808
Message #1985 Received: Hello world! from thread 25808
Message #1986 Received: Hello world! from thread 25808
Message #1987 Received: Hello world! from thread 25808
Message #1988 Received: Hello world! from thread 25808
Message #1989 Received: Hello world! from thread 25808
Message #1990 Received: Hello world! from thread 25808
Message #1991 Received: Hello world! from thread 25808
Message #1992 Received: Hello world! from thread 25808
Message #1993 Received: Hello world! from thread 25808
Message #1994 Received: Hello world! from thread 25808
Message #1995 Received: Hello world! from thread 25808
Message #1996 Received: Hello world! from thread 25808
Message #1997 Received: Hello world! from thread 25808
Message #1998 Received: Hello world! from thread 25808
Message #1999 Received: Hello world! from thread 25808
Message #2000 Received: Hello world! from thread 25808
Time to completion = 1.136 seconds.
-----------------------------------------------------
Finished with the example.
=====================================================



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值