如何构建 C++ 运行在带有 Visual Studio 2008 的普通 XP SP2 上并且没有并排 DLL 的应用程序?
我想通过一次调用 WinExec
来编译一个 C++ 项目,以便使用一些命令行参数启动另一个可执行文件。 我不知道要在我的项目中指定哪些设置才能生成不需要 Microsoft 并行 DLL 的可执行文件,而我不想将其安装在我的目标系统上。 有什么提示吗?
症状是应用程序无法启动,并且以下事件被写入应用程序日志(从法语免费翻译):
Error, SideBySide, event #33
Microsoft.VC90.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8" cannot be found.
更新:我知道使用 WinExec
是不好的做法,但它有效就像一个魅力,微软不可能在 API 的任何未来版本中删除它,不是吗?
I'd like to compile a C++ project with just a single call to WinExec
in order to launch another executable with some command line parameters. I've no idea what settings to specify in my project in order to get produce an executable that works without requiring Microsoft side-by-side DLLs, which I don't want to have to install on my target system. Any hints?
The symptom is an application which fails to start and the following event getting written to the application log (freely translated from French):
Error, SideBySide, event #33
Microsoft.VC90.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8" cannot be found.
UPDATE: I know that using WinExec
is bad practice, but it works like a charm, and Microsoft can't possibly remove it in any future release of the API, can't they?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您指定要静态链接运行时(/MT 或 /MTd),那么应该没问题。 项目属性->C/C++->代码生成->运行时库
If you specify that you want to statically link the run-time (/MT or /MTd) you should be good. Project Properties->C/C++->Code Generation->Runtime Library
如果您需要的只是 CreateProcess/ShellExecute(WinExec 自 NT 3.1/Win 95 起已弃用),则根本不需要任何运行时库。 在项目属性/配置/链接器/输入中启用忽略所有默认库并将kernel32.lib添加到其他依赖项。
If all you need is CreateProcess/ShellExecute (WinExec is deprecated since NT 3.1/Win 95), you don't need any runtime library at all. In Project Properties / Configuration / Linker / Input enable Ignore All Default Libraries and add kernel32.lib to Additional Dependencies.
jachymko 和 Josh 都(部分)回答了该解决方案。 这是完整的解决方案:
将项目属性/配置/链接器/输入/忽略所有默认库设置为是并添加
kernel32.lib
到其他依赖项。 仅此一项不会链接,因为代码会自动引用__security_check_cookie
和_WinMainCRTStartup
。删除/GS开关以指示编译器不要注入安全检查代码。 为此,请将项目属性/配置/C/C++/代码生成/缓冲区安全检查设置为否。
将项目属性/配置/C/C++/代码生成/运行时库设置为多线程(/MT)。
最初的 Visual Studio 2008 生成的代码包含一个名为
_tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
的入口点。 通过重命名它来修改它WinMain
并将第三个参数转换为LPSTR
。将项目属性/配置/链接器/高级/入口点设置为
WinMain
。通过对默认 C++ 项目进行这些更改,代码最终可以编译和链接,并在新安装的 Vista 或 XP(缺少运行时库)上运行。
The solution has been answered (partially) by both jachymko and Josh. Here is the full solution:
Set Project Properties / Configuration / Linker / Input / Ignore All Default Libraries to Yes and add
kernel32.lib
to Additional Dependencies. This alone won't link, as the code automatically refers to__security_check_cookie
and_WinMainCRTStartup
.Remove /GS switch to instruct the compiler not to inject the security check code. For this, set Project Properties / Configuration / C/C++ / Code Generation / Buffer Security Check to No.
Set Project Properties / Configuration / C/C++ / Code Generation / Runtime Library to Multi-threaded (/MT).
The initial Visual Studio 2008 generated code contains an entry point named
_tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
. Modify it by renaming itWinMain
and convert the third argument toLPSTR
.Set Project Properties / Configuration / Linker / Advanced / Entry Point to
WinMain
.With these changes to a default C++ project, the code finally compiles and links, and runs on a freshly installed Vista or XP, which lacks the runtime library.