C++ compiling with MS Visual Studio 2012

Soldato
Joined
8 Sep 2003
Posts
23,008
Location
150 yds from OcUK
Hi guys

I have decided to take it upon myself to self-teach myself programming.

I decided to jump in head first and go straight to c++ :)

Anyway I have been reading the basics etc and created three quite simple console programs based on integers and strings.

1. A simple program that you enter a number and it doubles it.
2. A simple currency converter - you enter the exchange and then enter a value and it works out the exchanged rate.
3. A simple data input method that asks you questions like what is your name, age etc and then uses that in the following responses etc.

None of it is cutting edge lol.

But I have compiled the .exe and they run fine on a PC with Visual Studio 2012 installed but didn't work on a PC without it - I got a work around by installing the latest c++ runtime library from Microsofts site.

But I cannot expect users to install the library as 95% of people won't know that they need to do this. Is there any way to embed the library in the .exe or make an installer for it.
 
Soldato
OP
Joined
8 Sep 2003
Posts
23,008
Location
150 yds from OcUK
I firstly did it in debug mode, but then changed it to release mode, and no change. Still the same issue.

Well if I clicked on the configuration Manager option and then changed the active solution to Release and the dropdown to release configuration too.

compiled_zps28d65d51.png


P.S. before you say anything I have just improved my code to
Code:
cout << "this is costing you " << exchange(x,y) << " pounds" << endl;
 
Associate
Joined
9 Jun 2004
Posts
423
You need to link statically to the runtime if you don't want to require people to have anything installed.

project properties -> c/c++ -> code generation -> choose multi-threaded debug or release as appropriate (non-DLL).

Of course, it makes the binaries bigger.

Installers can bundle the DLL runtimes too, but that's all very tedious and boring - avoid if you're just starting out :)
 
Soldato
OP
Joined
8 Sep 2003
Posts
23,008
Location
150 yds from OcUK
Perfect, thank you very much. I appreciate that!

It has made my .exe around 1mb which is high for a console app. haha, but its just me playing and learning, so doesn't matter. Eventually I will want to bundle the library files in with an installer.
 

Pho

Pho

Soldato
Joined
18 Oct 2002
Posts
9,325
Location
Derbyshire
Learn something new every day. I was running something the other day which had been compiled in debug mode and it needed me to install the debug libraries for it to work, figured it was that :p.

How come Microsoft don't bundle it all nowadays anyway?

Here is my first proper program. Simple but it does the job :)

Nice :). Here's a couple of tweak suggestions: how about next looking at validating the input; e.g. if I don't enter a number you should error and prompt me again, or if I enter 0 for the exchange rate it should error (rather than saying 1.INF or something due to the division by zero).
 
Soldato
Joined
6 Feb 2004
Posts
20,683
Location
England
I think they do

nope. there are plenty of applications built with VS 2005/2008/2010 that require the c++ runtimes for each different version. i'm not a programmer and i don't have VS installed but you can see the runtimes i have...

runtimes.PNG


i think they are patched by windows update for security/bugfixes but you have to install them yourself first.

if the application is large enough, they will bundle the runtime installer and silently run it as part of their own setup process. the other options are to link to the download on the MS site and get people to install it manually or statically link as you already know.

chances are most people will have them installed without even realising it. i know by time i've installed the intel drivers necessary for my motherboard, i have the c++ 2010 runtimes installed without having to do anything. :p
 
Soldato
Joined
6 Feb 2004
Posts
20,683
Location
England
that's normal. not a lot of software in the wild is compiled with VS2012.

originally VS2012 didn't even support building applications for windows XP. so i guess that put a great many people off using it.

there has been a update pushed out since its original release that supposedly supports XP but it's still not taken off yet. i'm guessing most VS2012 development is geared towards store apps for windows 8.
 
Soldato
OP
Joined
8 Sep 2003
Posts
23,008
Location
150 yds from OcUK
Yup, I just installed the latest, not realising that I would be in this situation.

I have the 30 day trial, what is best to use after the trial has expired. I don't fancy spending £400 on something that will just be used for fun.

And note my libraries. Loads of them.

library_zps0403f136.png
 
Soldato
Joined
6 Feb 2004
Posts
20,683
Location
England
if you're learning for fun, i'd start off with the free express version. you might find after a while you need the features found in the paid for version but at least by that point you'll know just how serious you are about getting into it and you'll know it will be money well spent.

also, depending on how serious you are, c++ might not be the best choice to start off with. if you're looking at a career change then i suppose it would be but if you're wanting to build a few little useful applications and not much more than that, i'd go with something like c#.

i should state i don't have any experience with either. i've just read that c++ has a much steeper learning curve.
 
Last edited:
Soldato
Joined
27 Apr 2012
Posts
4,067
Create an EMPTY project and not the bogstandard console template which includes all of the bloated **** which MSV2012 comes with. You should be able to send this out to people way easier without the need for all the fuss and libraries it drags with it.

New Project -> General -> Empty Project, then create your file (main.cpp) includes and away you go. Build in Release mode if you wish to send it out, Debug mode is with all the definitions and debug information tied along with the exe.
 

Pho

Pho

Soldato
Joined
18 Oct 2002
Posts
9,325
Location
Derbyshire
Unless you want to go down the embedded/Linux route then C# is pretty difficult to beat. It's very similar syntax and you can arguably do far more with it than C++*; ASP.NET websites, WCF webservices, Winforms, WPF etc.

* obviously C++ can do anything C# can but requires far more effort, websites aren't really written in C++ for a reason
 
Back
Top Bottom