简体   繁体   中英

Compiling a C code into a single executable compatible with both WinXP and Win7

I am trying to compile a C program into an executable compatible with both WinXP and Win7. Since the code needs to be as compact as possible, I'd like it to use DLLs. Visual Studio Express 2012 update4 can generate a code for WinXP, but the latter won't work on Win7. When running on Win7, I get the following error: "The program cant run because MSVCR110.dll is missing..."

Can anyone help me with this issue? Thanks in advance!

The program you compile under VS2012 should work on both XP and Windows 7. The problem is simply that the Windows 7 machine does not have the required runtime deployed on it. That is a prerequisite of linking against a dynamic runtime. You must deploy the runtime to any machine that runs the program.

Once you deploy the runtime, for instance by using the VS2012 redistributable package, you should find that you code will run. Note that you need to do this on all machines, not just Windows 7 machines. The fact that you have not had to do so on the Windows XP machine just means that some other application has already deployed the runtime there. Quite likely the XP machine is your development machine and the runtime was deployed when you installed Visual Studio.

As an alternative to installing the redistributable package you can simply place the runtime DLL, MSVCR110.dll, in the directory where your executable file lives. I recommend that you have a read of the documentation on this subject: Redistributing Visual C++ Files .

Note that if you really want to make the deployment as small and simple as possible, then linking against the dynamic runtime will not achieve that. You will find that static linking leads to the smallest and simplest deployment. Not that I am recommending that. For various reasons, the dynamic runtime is to be preferred.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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