在Windows上将Apache Portable Runtime (APR)编译为DLL

来源:互联网 发布:量子破碎剧情 知乎 编辑:程序博客网 时间:2024/04/30 06:44

    因最近要用到ActiveMQ的C++客户端ActiveMQ-CPP,需要在Windows下先编译APR。编译前需要下载解压APR,准备好Visual C++ 6.0。

    APR的源代码下载地址为http://apr.apache.org/,需要下载3个部分:APR、APR-util、APR-iconv的Win32源代码。一般下载最新版本即可。目前最新版本对应的文件名分别为apr-1.5.0-win32-src.zip、apr-iconv-1.2.1-win32-src-r2.zip、apr-util-1.5.3-win32-src.zip。将这3个文件下载到同一个目录下,例如D:\Apache。

    下载后将这3个文件分别解压到各自的目录,然后将这3个子目录去掉目录名里的版本号。即改名后的3个子目录分别为:D:\Apache\apr、D:\Apache\apr-iconv、D:\Apache\apr-util。这3个子目录名称必须是apr、apr-iconv、apr-util,不能为其它名称。

    在VC(推荐使用VC6,高版本的VC可能会碰到链接错误)里打开Workspace文件D:\Apache\apr-util\aprutil.dsw 。在Win32 Release模式下编译libaprutil这个工程,libaprutil依赖的libapr、libapriconv这2个工程会被自动编译。lib开头的工程生成DLL,非lib开头的工程生成静态库。编译成功后,可以分别在3个工程的Release目录下找到DLL文件:libapr-1.dll、libapriconv-1.dll、libaprutil-1.dll,以及LIB文件:libapr-1.lib、libaprapp-1.lib、libapriconv-1.lib、libaprutil-1.lib、xml.lib。


    在编译过程中可能会碰到以下错误:

错误1:找不到strings.h和inet.h

错误信息:
apr/include/apr_want.h(52): Could not find the file strings.h
apr/include/apr_want.h(121): Could not find the file arpa/inet.h
解决方法: 打开文件apr\include\apr_want.h,分别注释掉以下2行:
#include <strings.h>
#include <arpa/inet.h>


错误2:不支持LDAP v2.0
错误信息: ./include\apr_ldap.h(136) : fatal error C1189: #error :  Support for LDAP v2.0 toolkits has been removed from apr-util. Please use an LDAP v3.0 toolkit.
解决方法: 打开apr-util/include/apr_ldap.h ,注释此行:#error Support for LDAP v2.0 toolkits has been removed from apr-util. Please use an LDAP v3.0 toolkit.


错误3:找不到文件apr.h
错误信息:Could not find the file apr.h
解决方法:apr.h是编译时从apr.hw自动生成的,再次编译时此错误会自动消失。
0 0
原创粉丝点击