Qt USB通信--生成release版本

前面讲过Qt USB通信采用第三方开源库hidapi,那么当整个UI完成之后,我们就要发布我们的release版本。网上有众多Qt程序发布的资料,可以参考一下。生成.exe文件之后放到其他电脑无法执行。按照网上的资料说把改.exe文件所需要的dll添加到同一目录即可运行。

但是这里有个较为特殊的情况,因为hidapi.dll文件有关联到Windows下其他的dll文件并且与microsoft visual c++ runtime library有关,在其他电脑上运行会出现如下错误:

Qt USB通信--生成release版本_第1张图片

所以说简单的添加hidapi.dll还不够。

使用dependency这个软件来解析.exe文件所需的dll,发现hidapi.dll还需要用到MSVCR80D.dll文件,如图:

Qt USB通信--生成release版本_第2张图片

当我们把msvcr80d.dll添加进去后再用dependency解析后如图:

Qt USB通信--生成release版本_第3张图片

虽然此时hidapi.dll不再需要其他相关文件,但是还有提示错误:Side-by-Side configuration information....

记得前面使用hidapi库之前,我们用VS2005编译整个库,然后生成hidapi.dll和hidapi.lib两个文件用于Qt的项目工程,因此推测hidapi.dll与VS的环境有关。于是查找错误的原因。

1.首先是运行的错误代码0xc0150002.

通过Windows来查看程序运行的事件信息,右键“我的电脑”->“管理”->...如图

Qt USB通信--生成release版本_第4张图片

根据上面的提示信息:

Activation context generation failed for "C:\Users\User\Desktop\TCMTools4PC\hidapi.dll". Dependent Assembly Microsoft.VC80.DebugCRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="8.0.50608.0" could not be found. Please use sxstrace.exe for detailed diagnosis.
是Microsoft.VC80.DebugCRT这个没找到。还提示我们用sxstrace.exe去查看详细的原因。

用sxstrace.exe输出的结果是这样的(具体怎么用这个工具,请看http://blog.csdn.net/lly20000/article/details/8133584)

=================
Begin Activation Context Generation.
Input Parameter:
	Flags = 0
	ProcessorArchitecture = Wow32
	CultureFallBacks = en-US;en
	ManifestPath = \\tools\hidapi.dll
	AssemblyDirectory = \\CHM06\share\01.30\RELEASE\
	Application Config File = 
-----------------
INFO: Parsing Manifest File \\CHM06\share\01.30\RELEASE\hidapi.dll.
	INFO: Manifest Definition Identity is (null).
	INFO: Reference: Microsoft.VC80.DebugCRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="8.0.50608.0"
INFO: Resolving reference Microsoft.VC80.DebugCRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="8.0.50608.0".
	INFO: Resolving reference for ProcessorArchitecture WOW64.
		INFO: Resolving reference for culture Neutral.
			INFO: Applying Binding Policy.
				INFO: No publisher policy found.
				INFO: No binding policy redirect found.
			INFO: Begin assembly probing.
				INFO: Did not find the assembly in WinSxS.
				INFO: Attempt to probe manifest at C:\Windows\assembly\GAC_32\Microsoft.VC80.DebugCRT\8.0.50608.0__1fc8b3b9a1e18e3b\Microsoft.VC80.DebugCRT.DLL.
				INFO: Did not find manifest for culture Neutral.
			INFO: End assembly probing.
	INFO: Resolving reference for ProcessorArchitecture x86.
		INFO: Resolving reference for culture Neutral.
			INFO: Applying Binding Policy.
				INFO: No publisher policy found.
				INFO: No binding policy redirect found.
			INFO: Begin assembly probing.
				INFO: Did not find the assembly in WinSxS.
				INFO: Attempt to probe manifest at C:\Windows\assembly\GAC_32\Microsoft.VC80.DebugCRT\8.0.50608.0__1fc8b3b9a1e18e3b\Microsoft.VC80.DebugCRT.DLL.
				INFO: Attempt to probe manifest at \\CHM06\share\01.30\RELEASE\Microsoft.VC80.DebugCRT.DLL.
				INFO: Attempt to probe manifest at \\CHM06\share\01.30\RELEASE\Microsoft.VC80.DebugCRT.MANIFEST.
				INFO: Attempt to probe manifest at \\CHM06\share\01.30\RELEASE\Microsoft.VC80.DebugCRT\Microsoft.VC80.DebugCRT.DLL.
				INFO: Attempt to probe manifest at \\CHM06\share\01.30\RELEASE\Microsoft.VC80.DebugCRT\Microsoft.VC80.DebugCRT.MANIFEST.
				INFO: Did not find manifest for culture Neutral.
			INFO: End assembly probing.
	ERROR: Cannot resolve reference Microsoft.VC80.DebugCRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="8.0.50608.0".
ERROR: Activation Context generation failed.
End Activation Context Generation.

根据上面的信息,也是指向Microsoft.VC80.DebugCRT找不到。

上述查找问题原因的流程是参照这两篇文章的:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/a14a0157-fe32-430b-b9ab-50e4ecdd4116/sidebyside-cannot-find-80506080-redistributable?forum=vcgeneral

http://stackoverflow.com/questions/2361517/problem-with-visual-c-program-cant-find-the-debug-crt

前面有提到过我曾用VS2005编译hidapi这个库,那么是不是Microsoft.VC80.DebugCRT在VS2005的安装目录下呢?于是就去找了一下,还真被找到了。那个文件在VS安装目录下的:Microsoft Visual Studio 8\VC\redist\Debug_NonRedist\x86

把该文件拷贝过去后再运行.exe文件,立马该程序就妥妥的运行了。。。。

2.使用dependency的提示信息。

该提示信息都是指向同一个错误的。


总结:使用第三方库虽然方便,但是还要注意那个库是不是有依赖相关的平台。上面问题的查找不单单可以用到Qt软件版本的发布,也可以用到其他软件上面。当程序无法运行且有提示错误代码,就可以通过事件查看器来看看是什么原因,再去MSDN上查找解决方案。

你可能感兴趣的:(qt,软件发布,usb通信,hidapi)