Author Topic: all i want to do is run a C++ example  (Read 25827 times)

0 Members and 2 Guests are viewing this topic.

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18892
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
all i want to do is run a C++ example
« on: February 06, 2023, 10:34:47 pm »
I am so pissed off. I am trying to learn C++, -step one, copy the first example code that is about 1 sentence long into visual studio code, 2 discover that visual studio code with C++ tools installed does not have a C++ compiler, 3 go around and around in fucking circles trying to find out how to install C++ in visual studio and got no where except being told to download visual studio - what is the difference?. Seriously ? do coders just take the fucking piss all the time???

How can it be so hard to just install an IDE with compiler??? and my junior colleague thinks I am a jkbit weird for preferring bare metal programming.
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22435
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: all i want to do is run a C++ example
« Reply #1 on: February 06, 2023, 10:45:08 pm »
So... install plain ol' Studio?

VSC is a different beast, AFAIK.

An IDE is for editing and issuing commands, it's not necessarily the commands themselves.  Code::Blocks is another IDE without compiler; but it has presets for the major ones so it's very easy to drop one in.

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18892
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: all i want to do is run a C++ example
« Reply #2 on: February 06, 2023, 10:47:57 pm »
that's the problem. I can't "drop" a compiler in. what is the difference between VSC and VS? anythings else that makes sence? I take it codeblock is not that horrible thing microchip use for MPLABX?

All i want to do is run:

Code: [Select]
#include "std_lib_facilities.h"
int main() // C++ programs start by executing the function main
{
cout << "Hello, World!\n"; // output “Hello, World!”
keep_window_open(); // wait for a character to be entered
return 0;
}

I have spent the evening getting no where.
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18892
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: all i want to do is run a C++ example
« Reply #3 on: February 06, 2023, 10:51:07 pm »
how quaint, the C++ install is just a mere 14GB  :-DD
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 13031
  • Country: us
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18892
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: all i want to do is run a C++ example
« Reply #5 on: February 06, 2023, 11:05:20 pm »
https://code.visualstudio.com/docs/languages/cpp


Yes that particular page is useless and I can't work out if they are talking about VS or VSC, it's a joke!
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 6429
  • Country: nz
Re: all i want to do is run a C++ example
« Reply #6 on: February 06, 2023, 11:08:31 pm »
How can it be so hard to just install an IDE with compiler??? and my junior colleague thinks I am a jkbit weird for preferring bare metal programming.

Visual Studio Code is just an editor, not an IDE.

If you want an IDE, with compilers and stuff, install Visual Studio.

Or just use the built in command line tools on Mac or Linux rather than torturing yourself with Microsoft stuff. If you type "c++" on either one and it's not installed then it will tell you how to install it / offer to install it.
 
The following users thanked this post: Ed.Kloonk, JohanH, langwadt, KE5FX

Offline shapirus

  • Super Contributor
  • ***
  • Posts: 2254
  • Country: ua
Re: all i want to do is run a C++ example
« Reply #7 on: February 06, 2023, 11:24:31 pm »
How can it be so hard to just install an IDE with compiler??? and my junior colleague thinks I am a jkbit weird for preferring bare metal programming.
1. you don't want an IDE unless you know precisely why you want it for a particular task. using an IDE is a separate skill in itself. it needs its own learning course which wastes precious time, especially when you're a beginner. first learn to write programs, then learn to use an IDE, one of many, if you need it.

2. windows is not a programmer-friendly OS and is even less suitable for education, because it requires you to deal with a lot of stuff you don't immediately need. this is why and where many bail out and give up on learning to code right at the beginning.

see how easy it is to do what you want on linux:

1. copy&paste your code to a text file (normally done with a text editor, using cat here just for demonstration):

Code: [Select]
$ cat > example.cxx
#include <iostream>
int main() // C++ programs start by executing the function main
{
    std::cout << "Hello, World!\n"; // output “Hello, World!”
    return 0;
}

2. compile (and, strictly speaking, link in the same step)

Code: [Select]
$ g++ example.cxx -o example

3. run!

Code: [Select]
$ ./example
Hello, World!

doesn't require to install and configure a shitload of bloatware. doesn't require any mouse fiddling. doesn't get any easier and more efficient than this.
« Last Edit: February 06, 2023, 11:27:55 pm by shapirus »
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 6429
  • Country: nz
Re: all i want to do is run a C++ example
« Reply #8 on: February 06, 2023, 11:51:02 pm »
You forgot "apt install g++" :-)  Or yum or whatever your non-Debian based distro uses. But use Debian-based (Ubuntu etc) if you want an easy life. That includes people saddled with Windows, if they install WSL.

But I agree with you. IDEs are for when you're dealing with some massive, hundreds of thousands of lines, corporate monstrosity of a code base. If then. Absolutely not needed and really just gets in the way for anything you write yourself.
« Last Edit: February 06, 2023, 11:52:33 pm by brucehoult »
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 13031
  • Country: us
Re: all i want to do is run a C++ example
« Reply #9 on: February 06, 2023, 11:51:49 pm »
Yes that particular page is useless and I can't work out if they are talking about VS or VSC, it's a joke!

Visual Studio Code is a tool for experienced programmers, it is not really aimed at learners.

If you want a simple way to get started, you should look here instead:

https://visualstudio.microsoft.com/vs/community/

There are of course other options, but I can tell you for certain that Visual Studio Community edition is simple, straightforward and has all the features you need.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 13031
  • Country: us
Re: all i want to do is run a C++ example
« Reply #10 on: February 06, 2023, 11:55:44 pm »
You forgot "apt install g++" :-)  Or yum or whatever your non-Debian based distro uses. But use Debian-based (Ubuntu etc) if you want an easy life. That includes people saddled with Windows, if they install WSL.

But I agree with you. IDEs are for when you're dealing with some massive, hundreds of thousands of lines, corporate monstrosity of a code base. If then. Absolutely not needed and really just gets in the way for anything you write yourself.

Except as soon as you want to do something nontrivial, you will need to learn about makefiles, and then perhaps compiler options, and after that probably git, and before you know it you will be deep in the mire.

Anyone who tells you that programming is simple is being economical with the truth.
 
The following users thanked this post: newbrain, cfbsoftware

Offline shapirus

  • Super Contributor
  • ***
  • Posts: 2254
  • Country: ua
Re: all i want to do is run a C++ example
« Reply #11 on: February 07, 2023, 12:03:36 am »
You forgot "apt install g++" :-)
Correct. That would make a tiny bit of a homework to google for the error message in case g++ is not installed. Even that will not be required in a standard Ubuntu installation that has the "command-not-found" package installed by default which makes your shell suggest packages that contain the command that wasn't found but can be installed.

WSL.
That's correct. But using a real Linux installation is just so much better, if you have a choice (i.e., are not restricted by corporate policies and do not need to run some windows-specific software that fails to run under Wine).

Needless to say that all of this is my personal opinion, yet it's based on a good 25 years of experience.
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 6429
  • Country: nz
Re: all i want to do is run a C++ example
« Reply #12 on: February 07, 2023, 12:09:13 am »
You forgot "apt install g++" :-)  Or yum or whatever your non-Debian based distro uses. But use Debian-based (Ubuntu etc) if you want an easy life. That includes people saddled with Windows, if they install WSL.

But I agree with you. IDEs are for when you're dealing with some massive, hundreds of thousands of lines, corporate monstrosity of a code base. If then. Absolutely not needed and really just gets in the way for anything you write yourself.

Except as soon as you want to do something nontrivial, you will need to learn about makefiles, and then perhaps compiler options, and after that probably git, and before you know it you will be deep in the mire.

Anyone who tells you that programming is simple is being economical with the truth.

You can get a long way with a single source file.

And gcc foo.c bar.c baz.c qux.c -o foo will get you a lot further.

At some point, yeah, you could put that in a simple shell script, or a makefile. But that might be weeks or months in the future. I'd get started with git a lot sooner than that. Like 2nd day.

But the thing about it is you can learn things gradually as you need them, not everything all at once before you can run your first program.
 

Offline shapirus

  • Super Contributor
  • ***
  • Posts: 2254
  • Country: ua
Re: all i want to do is run a C++ example
« Reply #13 on: February 07, 2023, 12:19:20 am »
Except as soon as you want to do something nontrivial, you will need to learn about makefiles, and then perhaps compiler options, and after that probably git, and before you know it you will be deep in the mire.
Makefiles are actually next to trivial and very easy to learn. More complex build systems such as autoconf, cmake, etc. are more difficult, but they are not required until the project gets big and/or aims to be cross-platform compatible and become public.

Compiler options are learned and added as you need them. Defaults are fine, except that it is a good idea to use "-Wall -pedantic" right from the start.

Git will eventually become required no matter what ecosystem you choose, except when you opt for that Microsoft-made makeshift nonsense forced upon the unlucky ones (used to be called VSS, no idea how it's called now) that they created only to reinvent the wheel and avoid following one of the industry-standard solutions. And even then you still need to know a necessary minimum of Git.
But it's not required for a beginner playing around and making first steps on her/his local machine.

The good thing about the Linux ecosystem, or the Unix-style approach to programming and controlling the machine in general, is that you learn and begin to deal with each new entity only as it becomes needed. Step by step, simple to complex, perfect for learning.

Anyone who tells you that programming is simple is being economical with the truth.
Couldn't be said better.

Yes, programming IS simple. You just tell the machine what it has to do, can it be any simpler?
But there are certain nuances, which the beginner doesn't need to know right away -- that's what you called being economical with the truth :).
« Last Edit: February 07, 2023, 12:24:05 am by shapirus »
 

Offline rfclown

  • Frequent Contributor
  • **
  • Posts: 464
  • Country: us
Re: all i want to do is run a C++ example
« Reply #14 on: February 07, 2023, 03:59:48 am »
I don't do C++,  but I do C on the command line. Just use a text editor. I googled and followed instructions years ago for installing CodeBlocks for use with with command line. I see in my install folder that the file was codeblocks-17.12mingw-setup.exe. I don't use the IDE (maybe it's great, I don't know). I have a batch file called c.bat which is:
gcc %1.c -o %1.exe
so all I type to compile foo.c is "c foo". Yes, if I have to link other libraries and stuff, there's more to it, but for just getting going that's all you need.

I just tried to see if C++ worked also (I didn't explicitly install C++). I first tried your example, and it barfed on finding std_lib_facilites.h. Then I tried shapirus example, and it compiled fine. I typed:
g++ foo.c -o foo
and when running foo.exe got:
Hello, World!
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 6429
  • Country: nz
Re: all i want to do is run a C++ example
« Reply #15 on: February 07, 2023, 04:13:16 am »
I just tried to see if C++ worked also (I didn't explicitly install C++). I first tried your example, and it barfed on finding std_lib_facilites.h.

Googling says that's from a book by Stroustrup and you need to download it from his site:

https://www.stroustrup.com/Programming/std_lib_facilities.h
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3912
  • Country: it
Re: all i want to do is run a C++ example
« Reply #16 on: February 07, 2023, 06:43:14 am »
that's the problem. I can't "drop" a compiler in. what is the difference between VSC and VS? anythings else that makes sence? I take it codeblock is not that horrible thing microchip use for MPLABX?

All i want to do is run:

Code: [Select]
#include "std_lib_facilities.h"
int main() // C++ programs start by executing the function main
{
cout << "Hello, World!\n"; // output “Hello, World!”
keep_window_open(); // wait for a character to be entered
return 0;
}

I have spent the evening getting no where.

that would be Netbeans. Much less horrible than eclipse IMHO, too bad it lost traction to eclipse.
If it's very simple code, and don't need an executable and/or don't want to bother creating a project i usually go here
https://www.onlinegdb.com/online_c_compiler
(change the language to whatever suitable for your need)

Otherwise, because i have Qt already installed i create a Qt console Project. I can remove everything from Qt if i want to.

Another option is that you install by yourself MinGW (Use. The. Installer. Don't. Do. It. Manually.), with the installation manager it's a breeze, then you have GCC at the command line, can add GCC to VSCode (if you really want it, i don't understand those who diss netbeans or eclipse then praise VSCode, Everything seems a hack put together with spit and mud)

For a time i dabbled with Visual C++, but Visual studio, besides being a giant behemoth, has so many features i don't use, and i don't plan to ever use WPF or WinForms again, so it would be another giant IDE with its giant compiler taking up space. Qt takes enough space by its own
« Last Edit: February 07, 2023, 06:44:46 am by JPortici »
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 14124
Re: all i want to do is run a C++ example
« Reply #17 on: February 07, 2023, 09:19:05 am »
So its 13 months later and you haven't made any significant progress!  Take another look at your topic: https://www.eevblog.com/forum/programming/general-ide-to-learn-c-on/

We suggested several combinations of IDE and (usually) GCC based compilers which would give you less hassle and significantly smaller download size than anything recent from Microsoft. and discussed how to install them.  I even posted a zipped project of the "Hello World" program from chapter two of your book, that will work if you use the Bloodshed/Orwell/Embarcardo forks of the Dev-C++ IDE (or with any GCC based compiler from the command line).
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18892
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: all i want to do is run a C++ example
« Reply #18 on: February 07, 2023, 09:19:35 am »
I write programs just fine for micro controllers in microchip studio, now I just want to run the examples and exercises in a book to learn C++ that I will use on a micro controller in microchip studio the whole universe blows up |O
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18892
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: all i want to do is run a C++ example
« Reply #19 on: February 07, 2023, 09:22:24 am »
So its 13 months later and you haven't made any significant progress!
https://www.eevblog.com/forum/programming/general-ide-to-learn-c-on/

We suggested several combinations of IDE and (usually) GCC based compilers which would give you less hassle and significantly smaller download size than anything recent from Microsoft. and discussed how to install them.  I even posted a zipped project of the "Hello World" program from chapter two of your book, that will work if you use the Bloodshed/Orwell/Embarcardo forks of the Dev-C++ IDE (or with any GCC based compiler from the command line).

Correct, thought I was going round in the same circle again. I'm also not that interested in the IDE, but the discussion if I recall descended into which IDE is better and I just got lost. I just need to do the stuff in the book, at the end of the day I don't seem to have a choice of IDE , as everyone here points out they are hard work, so I'll be using whatever the micro controller manufacturer provides.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 14124
Re: all i want to do is run a C++ example
« Reply #20 on: February 07, 2023, 09:25:03 am »
I write programs just fine for micro controllers in microchip studio, now I just want to run the examples and exercises in a book to learn C++ that I will use on a micro controller in microchip studio the whole universe blows up |O

That's windows PCs for you - they've been a PITA to program on & for in C (or later C++) for the last 30 years.  You may notice a great theme throughout your old topic - the majority of us are pointing you at one 'flavour' or another of GCC rather than any Microsoft compiler!
« Last Edit: February 07, 2023, 09:28:02 am by Ian.M »
 

Offline Ed.Kloonk

  • Super Contributor
  • ***
  • Posts: 4000
  • Country: au
  • Cat video aficionado
Re: all i want to do is run a C++ example
« Reply #21 on: February 07, 2023, 09:30:36 am »
I just need to do the stuff in the book, at the end of the day I don't seem to have a choice of IDE , as everyone here points out they are hard work, so I'll be using whatever the micro controller manufacturer provides.

It's the debugging features that really make a IDE worthwhile. But at the end of the day, do what makes you happy.
iratus parum formica
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 14124
Re: all i want to do is run a C++ example
« Reply #22 on: February 07, 2023, 10:00:10 am »
I just need to do the stuff in the book, at the end of the day I don't seem to have a choice of IDE , as everyone here points out they are hard work, so I'll be using whatever the micro controller manufacturer provides.
So grab the Embarcardo fork of Dev-C++ which comes with a reasonably current GCC compiler, and grab the book-specific header file "std_lib_facilities.h" Brucehoult linked above, and have at it with the chapter two "hello World" example.  It should 'just work' - as it did for me 13 months ago.

Note that the zipped project (of this example) I posted back in reply #53 of your old topic is set up for the TDM-GCC 10.3.0 toolchain (which I posted installation instructions for back in reply #33) so if you choose to use that project with Embarcardo Dev-C++'s bundled Mingw GCC, you'd need to reselect the project toolchain.
 

Offline Brianf

  • Regular Contributor
  • *
  • Posts: 73
  • Country: gb
Re: all i want to do is run a C++ example
« Reply #23 on: February 07, 2023, 02:11:37 pm »
Why install anything?

https://godbolt.org/
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 11185
  • Country: fi
Re: all i want to do is run a C++ example
« Reply #24 on: February 07, 2023, 03:09:51 pm »
You got many good suggestions over a year ago:
https://www.eevblog.com/forum/programming/general-ide-to-learn-c-on/

You were also explained what VS Code is.

So it appears you ignored all the advice and now you are again pissed off, and probably unwilling to learn, again? What's different this time?

My advice is unchanged:
https://www.eevblog.com/forum/programming/general-ide-to-learn-c-on/msg3903872/#msg3903872
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf