user2098400
user2098400

Reputation: 31

creating C++ program that runs on most of PCs

I have a project that requires writing a code for small executable file. I used visual C++ express 2010 IDE to create this file. After I finished writing the code, I tried to copy it to a couple of different PCs. It gives me an error message every time I clicking on this file to execute it. The message states that I have to install (.NET framework). I watched a couple videos on YouTube explaining how overcome this problem by changing the runtime library from multi-threaded Debug DLL (/MDd) to multi-threaded Debug (/Mtd). However; the IDE can’t debug the C++ code because when I create my project by using CLR template! Is there any way to solve this problem? Can I create a similar program that not requires any further downloading once I using on different PC?

Is learning a different language like JAVA or C# will help creating small programs (like my program) that run on most Window platform machine?

Upvotes: 3

Views: 411

Answers (5)

allen
allen

Reputation: 4647

You seem to have created a Managed C++ Project. Instead create an empty Win32 C++ project and then add in your .cpp/.h files. This will limit you to the default libraries available on all PCs with the C++ runtime. If you want to remove that dependency too then statically compile in the runtime using the /MT option. Details @ http://msdn.microsoft.com/en-us/library/2kzt1wy3(v=vs.71).aspx

As you move ahead you would need to be conscious of what libraries you take dependencies on and what versions of the OS are those libraries available on or if you need to package them with your bits.

Upvotes: 1

Nayana Adassuriya
Nayana Adassuriya

Reputation: 24766

Note: It is possible to run C++ program in any computer without installing anything if you haven't use .NET framework. In your case, there can be two reasons to trigger error in target computer.

  1. New computer doesn't have required run-time assembles.
  2. New computer doesn't have required .NET framework installed.

..........................................

So what to do:

  1. Before start your program you have to design weather are you going to use .NET framework support or not. If you use .NET framework when you develop your program, then you much install same or higher .NET framework in target computer.

  2. If you no need to use .NET component then your target computer should only containing run-time assemblies. How to get rid of .net framework

    • right click on the project in solution -> properties -> General -> Common language run time support -> select "No common language run time support".

..........................................

Then what you need is only relevant run-time assemblies be in target computer.

How can run-time assemblies be in new computer:

There are two ways:

  1. Install suitable C++ disputable environment in target computer(if you use VS2008 SP1, C++ RD package should be this. Please consider the solution build architecture also (32 bit/64 bit) before download ).

  2. Deploy run-time assemblies with your solution package. (I like this because user no need to install any third party components)

..........................................

How Deploy assemblies with my project:

  1. for this your all DLL, LIB, EXE should use same run time version.(if not, you face troubling to redirect assemblies by 'manifest' files ).

  2. How to check the run-time version. open DLL,EXE by visual studio (open->file) -> expand RT_MANIFEST-> double click the file under it ->then assembly dependency details will open. -> copy the data in right column and paste to note pad.

You will see this kind of line there. and ther is the version run-time assemblies your specific DLL or EXE use.

assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86".....

After identifying the version of run-time assemblies follow this tutorial and try to run in fresh installed computer.

At last: If you think this bla.. bla.. is so complex and your program is very simple, then you can consider about "run time assemblies statically linking" (try Google). But personally I don't like this method.

good luck!

Upvotes: 0

dtech
dtech

Reputation: 49279

Just use Qt - it runs on Windows, Linux, MacOS, support for Android and iOS is scheduled for this year, plus it supports embedded platforms and some of the more obscure mobile platforms. Also, support for Windows RT was just kickstarted. A complete library with tons of functionality, good documentation and lots of educational resources. It provides tons of tools, from implicitly shared containers through threading, signals and slots, 2D and 3D graphics, widgets, multimedia, sensors... and whatnot...

You can even develop commercial applications under the LGPL license.

Also comes with a pretty good IDE - Qt Creator.

You can develop standard C++ applications or use QML, which is a JavaScript like language for markup and scripting, which is used to build applications from C++ implemented components. You can also extend QML. It is much faster to develop with QML and you still get the advantages of platform native binary under the hood.

Note that you will still need to either ship a few DLLs with your application. Unless of course you use a static build, which requires you to either have your application open source, or purchase a commercial license... which doesn't come cheap...

But still, a few MB of DLLs are far better than the entire .NET framework. A static build will produce executables about 8-9 MB with no external dependencies.

Upvotes: 7

Matthias
Matthias

Reputation: 8180

Stick with the C++ standard, avoid Microsoft extensions (managed code), and call only POSIX functions of your OS, then you should be able to write portable programs.

Upvotes: 3

user1095108
user1095108

Reputation: 14603

Both Java and C# will help making portable programs. Usually, people will have to install runtime environments for executables written in these two languages, however. These days, C++ is more portable than ever. You can easily run C++ executables in your browser:

https://github.com/kripken/emscripten

http://code.google.com/p/nativeclient/

This makes many of the reasons why Java and C# came about irrelevant.

Open standards like OpenGL also make portable GUI programming easier than ever. Try Qt, if you want to write a simple GUI in C++.

Upvotes: 0

Related Questions