在C ++中创建一个自包含的程序 [英] Create a self-contained program in C++

查看:371
本文介绍了在C ++中创建一个自包含的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Visual Studio 2012.我希望创建一个完全独立的程序,可以在没有可视工作室的机器上使用,只需直接复制exe文件即可。我以前需要首先运行visual c ++ 2012可再发行以使程序工作。有什么办法使一切运行在一个exe?我不想使用安装程序,因为它是一个相当简单的程序;用户使用安装程序所需的时间可能会超过我的程序...



所以有什么办法静态链接一切吗?现在,它只是在新机器上运行时崩溃,但是一旦我在该机器上安装VS2012 express,它突然开始工作。



任何帮助将不胜感激。

解决方案

要在MFC项目中获得静态链接,请按以下方式设置项目属性

C / C ++代码生成,运行时库:多线程(/ MT)



配置属性,一般:使用MFC :使用MFC是一个静态库



一个简单的exe与这些属性将独立运行。


I'm using Visual Studio 2012. I wish to create a completely self-contained program that can be used on a machine without visual studio installed just by copying the exe file directly. I used to need to first run visual c++ 2012 redistributable to make the program work. Is there any way to make everything run in one exe? I would not like to use an installer either as it is a fairly simple program; the time it takes for the user to use the installer will probably be more than my program...

So is there any way to statically link everything? Right now, it just crashes when run on a new machine, but once I install VS2012 express on that machine, it suddenly starts to work.

Any help would be appreciated.

解决方案

To get static linking in an MFC project set the project properties (for the release build) as follows:

C/C++ Code Generation, Runtime Library: Multi-threaded (/MT)

Configuration Properties, General: Use of MFC: Use MFC is a Static Library

A simple exe with these properties will run standalone.

这篇关于在C ++中创建一个自包含的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆