之前小朱在http://blog.csdn.net/m_star_jy_sy/article/details/7479498记录了编译Xalan-C的过程.
当时只编译了Debug版本.现在需要Release版本.
编译过程比预想的困难许多.记录如下.
(初始编译过程是基于上面链接内容进行的)
编译Xalan-C++的官方资料http://xml.apache.org/xalan-c/build_instruct.html#win32.
1.目标
目标如下:
- 编译Debug和Release版本
- wchar_t作为内置类型
Xercesc也按此选项编译.
Xalan主目录用$XALANROOT表示.
2.过程记录
首先编译Debug版本.
(1)编译Locatization
在"属性页|配置属性|NMake|预处理器定义"中增加:
XALAN_USE_NATIVE_WCHAR_T
$XALANROOT\c\Projects\Win32\VC8\Utils目录结构及文件:
--Localization:
BuildMessages.mak
--MsgCreator
MsgCreator.mak
--XalanMsgLib
XalanMsgLib.mak
修改上面3个make文件,把文件内容中的"VC7.1"全部替换为"VC8" .
编译时出现XMLCh,UTF16Ch类型不能进行类型转换的错误时,修改代码强制转换.
相关的类型定义如下:
//src\xercesc\util\compi;ers\vcppdef.hpp
// ---------------------------------------------------------------------------
#ifdef _NATIVE_WCHAR_T_DEFINED
typedef wchar_t XMLCh; /// !!!
#else
typedef unsigned short XMLCh;
#endif
// ---------------------------------------------------------------------------
// Define unsigned 16 and 32 bits integers
// ---------------------------------------------------------------------------
typedef unsigned short XMLUInt16;
//src\xercesc\util\xercesdefs.hpp
typedef XMLUInt16 UTF16Ch;
出现link错误(U1077)时,
1>正在执行生成文件项目操作
1>Microsoft (R)
1>Used BITS = Win32
1>Used CFG = Debug
1>Used LOCALE = en_US
1>Used TYPE = inmem
1>Used XLIFF file: "XalanMsg_en_US.xlf"
1>Microsoft (R)
1> link.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\1\nm3F9.tmp
1> ..\..\..\..\..\Build\Win32\VC8\Debug\MsgCreator.exe ..\..\..\..\..\src\xalanc\NLS\en_US\XalanMsg_en_US.xlf -TYPE inmem -LOCALE en_US
1>NMAKE : fatal error U1077:
1>Stop.
1>Project : error PRJ0019: 工具从"正在执行生成文件项目操作"
在$XALANROOT\\c\Projects\Win32\VC8\Utils\MsgCreator目录下执行:
MsgCreator.exe ..\..\..\..\src\xalanc\NLS\en_US\XalanMsg_en_US.xlf -TYPE inmem -LOCALE en_US
报错,提示没xerces-c_2_8D.dll.
复制xerces-c_2_8D.dll到$XALANCROOT\\c\Projects\Win32\VC8\Utils\MsgCreator后再执行成功.
最终生成所需的XalanMessage_1_10D.dll
(2)编译AllInOne
"工程属性|配置属性|C/C++|预处理器定义"增加:XALAN_USE_NATIVE_WCHAR_T修改目录从VC7.1到VC8.
"工程属性|配置属性|常规"中输出目录和中间目录.
"工程属性|配置属性|预编译头"中预编译头文件.
"工程属性|配置属性|C/C++|输出文件"中ASM列表位置,对象文件名,程序数据库文件名.
"工程属性|配置属性|链接器|常规"的输出文件.
"工程属性|配置属性|链接器"的附加库.
"工程属性|配置属性|链接器|高级"的导入库.
生成Xalan-C_1_10D.dll,XalanMessages_1_10D.dll
3.编译Release版本
修改$XALANROOT\c\Projects\Win32\VC8\Utils\Localization\toos.ini
#[NMAKE]
CFG=Release ;恢复此行
否则在清理工程时报以下错误:
1>Microsoft (R)
1>Used BITS = Win32
1>BuildMessages.mak(32) : fatal error U1050: Invalid configuration CFG="" specified.
1>Stop.
1>Project : error PRJ0019: 工具从"正在执行生成文件项目操作"
修改MsgCreator.mak
CPP_PROJ增加:
/D "XALAN_USE_NATIVE_WCHAR_T"
CPP_PROJ的内容为:
CPP_PROJ=/nologo /MD /W4 /GX /O2 /I ".\\" /I $(XALANINCLUDE) $(XERCESINCLUDE) /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "XALAN_USE_NATIVE_WCHAR_T"
/Fp"$(INTDIR)\MsgCreator.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
修改XalanMsgLib.mak
CPP_PROJ增加:
/D "XALAN_USE_NATIVE_WCHAR_T"
CPP_PROJ的内容为:
CPP_PROJ=/nologo /MD /W4 /GX /O2 $(XERCESINCLUDE) /I "..\..\..\..\..\src" /I ".\$(BUILDRESDIR)\Nls\Include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS"
/D "_USRDLL" /D "XALANMSGLIB_EXPORTS" /D "XALAN_XALANMSGLIB_BUILD_DLL" /D "XALAN_USE_NATIVE_WCHAR_T" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
注:
编译Debug版本时,在"属性页|配置属性|NMake|预处理器定义"中增加:XALAN_USE_NATIVE_WCHAR_T.
----这个设置在编译Release版本时没有起作用.
目前也不确定在Debug中是否起作用了.待验证.
(1)编译Locatization
修改$XALANROOT\c\src\xalanc\XalanTransformer\XalanCAPI.cppXALAN_TRANSFORMER_EXPORT_FUNCTION(void)
XalanSetStylesheetParamUTF(
const XalanUTF16Char* key,
const XalanUTF16Char* expression,
XalanHandle theXalanHandle)
{
getTransformer(theXalanHandle)->setStylesheetParam(
XalanDOMString(key, XalanMemMgrs::getDefaultXercesMemMgr()),
XalanDOMString(expression, XalanMemMgrs::getDefaultXercesMemMgr()));
}
修改为:
#include <xalanc/Include/PlatformDefinitions.hpp>
XALAN_CPP_NAMESPACE_USE
XALAN_TRANSFORMER_EXPORT_FUNCTION(void)
XalanSetStylesheetParamUTF(
const XalanUTF16Char* key,
const XalanUTF16Char* expression,
XalanHandle theXalanHandle)
{
getTransformer(theXalanHandle)->setStylesheetParam(
XalanDOMString((XalanDOMChar*)key, XalanMemMgrs::getDefaultXercesMemMgr()),
XalanDOMString((XalanDOMChar*)expression, XalanMemMgrs::getDefaultXercesMemMgr()));
}
否则,编译出错,提示没有匹配的构造函数.
(2)编译AllInOne
出现以下错误:
2>正在嵌入清单...
2>mt.exe : general error c101008d: Failed to write the updated manifest to the resource of file "..\..\..\..\Build\Win32\VC8\Release\Xalan-C_1_10.dll". f
2>项目 : warning PRJ0018 : 未找到下列环境变量:
2>$(XERCESCROOT)
"项目属性|配置属性|清单工具输入和输出"中,把嵌入清单改成否.
解决方法来自
http://hi.baidu.com/osidy/item/2b1a2af7cc3528ce521c264e
其中的以下内容说明了可能的原因:
Hi,
This might be due to antivirus holding open handle on the exe generated and thus when VS tries to embed the manifest it fails with access denied.
Is Antivirus running on your machine? Does this repro with Antivirus turned off?
If above is not the case can you provide us with a repro.
Thanks,
VC++ Team
至此,Xalan-C_1_10.dll,XalanMessages_1_10.dll及lib文件编译完成.
整个过程修改的源文件有:
xalanc\Indlude\PlatformDefinitions.hpp
xalanc\Utils\MsgCreator\ICUResHandler.cpp
xalanc\Utils\MsgCreator\MsgFileOutputStream.cpp
xalanc\Utils\MsgCreator\NLSHandler.cpp
xalanc\Utils\MsgCreator\SAX2Handler.cpp
xalanc\XalanTransformer\XalanCAPI.cpp