简体   繁体   English

如何在任何Windows计算机上运行.exe文件?

[英]How can I run a .exe file on any Windows computer?

My friend wanted me to make him this program and he is not very tech savvy. 我的朋友要我给他做这个程序,他不是很精通技术。 How can I make the .exe run without making him download anything extra? 我如何才能运行.exe而又不让他下载任何额外内容? It was coded in C++ on Visual Studio. 它是在Visual Studio上用C ++编写的。

If your program uses anything from the standard library, it will need the Visual C++ runtime library, which is typically loaded from the library DLLs (something like msvcr110.dll ). 如果您的程序使用标准库中的任何内容,则将需要Visual C ++运行时库,该库通常是从库DLL(类似于msvcr110.dll )加载的。

However you can instruct the compiler (the linker , rather) to include (I do not mean #include-ing the header file) the library as part of your executable ( exe file). 但是,您可以指示编译器 (而不是链接器 )将库(作为我的意思是#include-header文件)作为可执行文件( exe文件)的一部分包含在内。 (I guess you thought of ISO because an archive file would include all the necessary DLLs) According to https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx , use the /MT compiler option will cause the "multithreaded, static version" of the Visual C++ runtime library (which is the library in pre-compiled code) to be included in your program during linking (in contrast to the default /MD option, which only causes code that helps your program link to the main library DLL to be included). (我想您想到了ISO,因为存档文件将包含所有必需的DLL)。根据https://msdn.microsoft.com/zh-cn/library/2kzt1wy3.aspx ,使用/ MT编译器选项将导致“ Visual C ++运行时库(预编译代码中的库)的多线程静态版本”将在链接期间包含在您的程序中(与默认的/ MD选项相反,后者只会导致有助于您的程序链接到的代码主库DLL)。

Correction : The program will be larger, but since the linker does not actually add everything to the output program, the size of the output file depends on what the program uses. 纠正措施 :程序将更大,但是由于链接程序实际上并未将所有内容添加到输出程序中,因此输出文件的大小取决于程序使用的内容。 Microsoft Visual Studio ~ C/C++ Runtime Library ~ Static/dynamic linking This might be helpful. Microsoft Visual Studio〜C / C ++运行时库〜静态/动态链接这可能会有所帮助。 (If you are interested, look into Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\lib (don't forget to replace the version number).) (如果您有兴趣,请查看Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\lib (不要忘记替换版本号)。)

Go to project settings -> configuration properties -> C/C++ -> code generation and set runtime library to Multi-threaded (MT) . 转到项目设置->配置属性-> C / C ++->代码生成,并将runtime library设置为Multi-threaded (MT)

Correction : it seems directly setting the compiler flag will work even with the default /MD or /MDd flag left in the command line. 更正 :即使直接在命令行中保留默认的/ MD或/ MDd标志,似乎直接设置编译器标志可以使用。

EDIT : be sure to clean the solution (build -> clean solution) after applying these settings. 编辑 :请确保在应用这些设置后清洗溶液(构建->清洗溶液)。 Otherwise the linker may still try to use the old files. 否则,链接器可能仍会尝试使用旧文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM