当前位置: 首页 > 工具软件 > ActiveMQ-CPP > 使用案例 >

编译ActiveMQ-CPP库遇到的那点事

沈俊美
2023-12-01

编译ActiveMQ-CPP库遇到的那点事

工作需要,需要编译ActiveMQ-cpp库,现将编译过程中遇到的问题及解决办法记录下来,以供他人参考,少走弯路。
ActiveMQ-CPP从2.2版本以后依赖Apache Portable Runtime项目,所以在编译之前需要先编译apr库。
从Apache Portable Runtime项目官网上下载最新的APR源代码,截至目前,最新的APR版本为1.7.0。

编译,遇到以下错误:

cl.exe /nologo /MD /W3 /Zi /O2 /Oy- /I "./include" /I "./include/arch" /I "./include/arch/win32" /I "./include/arch/unix" /I "./include/private" /D "NDEBUG" /D "APR_DECLARE_STATIC" /D "WIN32" /D "WINNT" /D "_WINDOWS" /Fo".\x64\LibR\\" /Fd".\x64\LibR\apr-1" /FD /c .\atomic\win32\apr_atomic.c 
apr_atomic.c 
        cl.exe /nologo /MD /W3 /Zi /O2 /Oy- /I "./include" /I "./include/arch" /I "./include/arch/win32" /I "./include/arch/unix" /I "./include/private" /D "NDEBUG" /D "APR_DECLARE_STATIC" /D "WIN32" /D "WINNT" /D "_WINDOWS" /Fo".\x64\LibR\\" /Fd".\x64\LibR\apr-1" /FD /c .\dso\win32\dso.c 
dso.c 
e:\apr-1.7.0\include\arch\win32\apr_arch_misc.h(503): error C2143: syntax error: missing ')' before '*' 
e:\apr-1.7.0\include\arch\win32\apr_arch_misc.h(503): error C2143: syntax error: missing '{' before '*' 
e:\apr-1.7.0\include\arch\win32\apr_arch_misc.h(503): error C2059: syntax error: ')' 
e:\apr-1.7.0\include\arch\win32\apr_arch_misc.h(503): error C2061: syntax error: identifier 'apr_winapi_pfn_if_indextoname' 
e:\apr-1.7.0\include\arch\win32\apr_arch_misc.h(503): error C2059: syntax error: ';' 
e:\apr-1.7.0\include\arch\win32\apr_arch_misc.h(503): error C2513: ' ': no variable declared before '=' 
e:\apr-1.7.0\include\arch\win32\apr_arch_misc.h(503): error C2065: 'apr_winapi_pfn_if_indextoname': undeclared identifier 
e:\apr-1.7.0\include\arch\win32\apr_arch_misc.h(503): warning C4047: '=': 'int' differs in levels of indirection from 'int *(__cdecl *)(NET_IFINDEX,PCHAR)' 
e:\apr-1.7.0\include\arch\win32\apr_arch_misc.h(503): error C2146: syntax error: missing ';' before identifier 'apr_load_dll_func' 
e:\apr-1.7.0\include\arch\win32\apr_arch_misc.h(503): error C2100: illegal indirection 
e:\apr-1.7.0\include\arch\win32\apr_arch_misc.h(503): error C2064: term does not evaluate to a function taking 19 arguments 
e:\apr-1.7.0\include\arch\win32\apr_arch_misc.h(503): warning C4033: 'apr_winapi_if_indextoname' must return a value 
NMAKE : fatal error U1077: '"d:\Program Files (x86)\Microsoft Visual Studio 2017\VC\Tools\MSVC\14.14.26428\bin\HostX64\x64\cl.exe"' : return code '0x2' 
Stop. 

解决办法:在include文件夹下找到apr.hw文件,以文本方式打开,找到宏定义“#define _WIN32_WINNT 0x0501”,将0x0501改为0x0600。至于为什么改成0x0600,笔者也是参考了一个网址编译APR报错

继续编译,然后遇到错误“找不到apr_escape_test_char.h头文件”。
解决办法:可以自己新建一个头文件,内容如下:

/* this file is automatically generated by gen_test_char, do not edit. "make include/private/apr_escape_test_char.h" to regenerate. */
#define T_ESCAPE_SHELL_CMD     (1)
#define T_ESCAPE_PATH_SEGMENT  (2)
#define T_OS_ESCAPE_PATH       (4)
#define T_ESCAPE_ECHO          (8)
#define T_ESCAPE_URLENCODED    (16)
#define T_ESCAPE_XML           (32)
#define T_ESCAPE_LDAP_DN       (64)
#define T_ESCAPE_LDAP_FILTER   (128)

static const unsigned char test_char_table[256] = {
    224,222,222,222,222,222,222,222,222,222,223,222,222,223,222,222,222,222,222,222,
    222,222,222,222,222,222,222,222,222,222,222,222,6,16,127,22,17,23,49,17,
    145,145,129,80,80,0,0,18,0,0,0,0,0,0,0,0,0,0,16,87,
    119,16,119,23,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,23,223,23,23,0,23,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,23,23,23,17,222,222,222,222,222,222,222,222,222,222,222,222,222,
    222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,
    222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,
    222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,
    222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,
    222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,
    222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222 
};

虽然注释说这个头文件是自动产生的,不要修改,水平有限,笔者不知道这个文件如何生成,直接拿来用时并没有发现其它问题。继续编译,OK,大功告成,成功编译出apr-1.lib静态库。

接下来编译ActiveMQ-CPP则较为简单,需要将上面编译好的APR库include文件下的头文件及.lib库添加到ActiveMQ-CPP的工程属性中。

 类似资料: