我正在开发一个使用XML文件的Qt应用程序。为了提高性能,我使用的是pugixml解析器而不是Qt的dom解析器。编译之后,我的应用程序和所有依赖项(dll文件,帮助程序)被打包为winapi应用程序的资源,以创建单个exe文件。
在我需要将QString::toStdString()
替换为QString::toStdWString()
之前,一切正常。原因是将名称(ąęśćłóźżń
)中带有扩展字母的文件读入pugixml。我使用先前由Qt递归目录循环加载的数据运行pugixml::document::load_file()
。包含文件名的QString
将转换为std::wstring
,然后转换为const wchar_t*
qstring.toStdWString().c_str()
。
用string
替换wstring
后,解压后的可执行文件运行良好。但是,打包后,最终的.exe文件有一个损坏的清单,如下所示:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker"/>
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates application support for Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!--The ID below indicates below indicates application support for Windows
7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!--The ID below indicates application support for Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!--The ID below indicates application support for Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!--The ID below indicates application support for Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibili
我正在使用Windows 7 64位,使用MinGw -w64 shell进行编译。最终包的makefile如下所示:
all: final.exe
final.exe: sad.o res.o
g++ -o final.exe -static-libgcc sad.o res.o resource.o -lcomctl32 -lshlwapi -mwindows
sad.o: sad.cpp
g++ -c sad.cpp
res.o: sad.rc resource.h resource.cpp
windres sad.rc res.o
g++ -c resource.cpp
clean:
rm -f *o final.exe
(res.o
包含程序和windres打包的所有依赖项,sad.cpp
包含从资源调用我的应用程序的winapi程序。
答案 0 :(得分:0)
不确定导致问题的原因,似乎是编译器错误,但是可以通过从包含有效清单的xml文件创建winapi资源来解决它。我将描述该程序以供将来参考。
创建一个新的manifest.rc文件,如下所示:
#include <windows.h>
RT_MANIFEST BINARY MOVEABLE PURE "manifest.xml"
然后创建一个包含有效清单XML文件的manifest.xml文件并添加到Makefile:
manifest.o: manifest.rc
windres manifest.rc manifest.o
不要忘记将manifest.o添加到Makefile中的主程序配方:
final.exe: sad.o res.o manifest.o
g++ -o final.exe -static-libgcc sad.o res.o resource.o manifest.o -lcomctl32 -lshlwapi -mwindows