So, I just recently started learning C++ and my cousin said that a good IDE was VScode. So, I installed VScode, downloaded the extensions that supported C++, and wrote my programs and got this:
"g++" is not recognized as an internal or external command.
what do I do here? I have looked at other questions that ask the same questions, but all of them mainly say to download a compiler like MinGW (Which I already have) and CygWin (also have downloaded this one). So what do I do?
Based on the OS, you need to add path to g++ to PATH variable.
Check ~/.profile file?
Also check:
https://github.com/microsoft/vscode-cmake-tools/issues/576
Related
I downloaded the C++ extension of Visual Studio. How do I save it and how do I open it to see my code?
Usually, with HTML, I save as .html and when I open the file, I can see it on google chrome
see image
C++ is very very different from HTML. HTML can, as you know, easily be opened in a browser and viewed.
C++ is a programming language and must be compiled and run. There are many ways to do this and largely depends on the operating system you are using and software you have installed.
Since you are using VSCode you will likely want to use the terminal to compile and run it. Try looking at something like g++. You can find lots of tutorials online just by googling "compiling c++".
You may find it easier when just starting out with C++ to try it out a bit using a site such as repl.it which will let you write simple programs fairly easily.
If you provide a bit more info such as which operating system you are on I can help provide a specific example.
Will split my answer into three main points:
Small introduction.
Installation.
Additional resources.
Small Introduction
C++ works differently than HTML.
The main difference (there are more!) is that C++ files need to be compiled before they can be used. And that requires a compiler.
There are various compilers available for C++.
Installation
Assuming that OP is using Windows, assuming that VS Code is installed, there are a few additional requirements:
Install C++ extension for VS Code (this one).
Install the latest version of Mingw-w64 (from here). This one provides one with up-to date builds of GCC, Mingw-w64, and other C++ tools/libraries. Make sure you follow all the steps mentioned in MSYS2 installation guide (for a detailed installation guide go here).
Add Mingw-w64 bin folder to Windows PATH environment variable.
3.1. Access Settings and type in the search bar "Edit environment variables for your account"
3.2. In the User variables, select the Variable Path and click Edit.
3.3. Add the location of the Bin folder, the default should be C:\msys64\mingw64\bin and click OK.
Note: In order to check if the installation was successful, open a new CMD window, and run g++ --version. The output should look like
If one runs gdb --version the output should be
You are now ready to go.
Additional resources
If you want to learn how to create Hello World using C++ on VS Code, go here.
Additional resources that may be relevant:
GCC on Windows
For GCC on Linux
For GCC on WSL (Windows Subsystem for Linux)
There are plenty of C++ online compilers that one might want to use for faster testing, such as W3Schools. These can be quite handy as they allow one to view the result in one's browser.
I'm working on developing my own programming language, and to generate executables I wished to convert the source to C++ and the run it through a C++ compiler.
Does anybody know of a C++ compiler which I can simply include with my application and then invoke from the command line without installation?
I'm using Windows.
Thanks in advance, Tom.
Edit:
It seems gcc is the way to go and it would be a pain to set up, would people recommend bundling the installation file instead and then installing the compiler as part of the installation of my program?
Have you tried gcc (the windows port)?
Over the last couple of months I practiced console programming with Java just with the help of JDK and a text editor of my choice (Notepad++). And I loved the simplicity as a program can be compiled from the command line plainly using javac and run using java.
Now, I'm looking for similar compiler for C/C++, such that I create a .c or .cpp file and compile it in the command prompt, and all it does is create a "native" executable that can be run directly from the command prompt. Thus, without any need of bloated IDE. The reason I'm looking for such simple compiler is because it is going to be used by high-school students so I'm advised to avoid any IDE as far as possible, so students can practice all the concepts of C/C++ languages without having to go for IDE. Which compiler can I use that does this job? also, I must work across all the versions Windows starting from Windows XP.
You can download MinGW which is basically GCC for windows.
Then you can simply gcc somefile.c to create an executable.
http://gcc.gnu.org/gcc is a multi platform c/c++ compiler
Visual Studio includes the ability to compile from the command line. Like others just said you can look at cygwin/MinGW. I would recommended using Code::Blocks or Dev-C++. I know you stated you do not want an IDE, but I would highly suggest a minimalist IDE like the ones I just suggested, or at least SciTE or Notepad++ to get some basic syntax highlighting with the ability to configure build tools if you want as well.
MinGW GCC is definitely the way go, but I would recomend the nuwen.net distro (http://nuwen.net/mingw.html). Haven't used it in a while (yay unix!), but if IIRC, it comes with everything ready to go after unpacking. The official distribution is ... very hard to get working.
A very simple solution woul be cygwin and MinGW, which provides an environment very similar to a UNIX shell. Then you can use the make utilities to compile your program.
You should certainly consider using MinGW GCC, but not by download from the MiNGW web page, unless you are some kind of masochist. Get the one packaged by Twilight Dragon Media at http://tdm-gcc.tdragon.net.
I too use VisualStudio on Windows from the command prompt and use VS Make files as well. That way, I can smb mount my source code from a different machine and perform compiles on several different platforms at once (e.g. Windows, Linux, Solarsi).
I have recently started learning C++, but I require a compiler. I have tried the one packaged with Code::Blocks, but I have been told it is out of date.
I have tried reading the instructions on the website, but I simply don't know which files to download and un-zip. Is there a list of files to download? (latest version) and a folder structure I need?
I was the person that pointed you at the more up-to-date version at Twilight Dragon. The file you want there is http://sourceforge.net/projects/tdm-gcc/files/TDM-MinGW%20Installer/1.908.0/tdm-mingw-1.908.0-4.4.1-2.exe/download which is a Windows binary installer - you just run it. Note that you don't actually need to do this - the version that comes with Code::Blocks will work OK for someone starting to learn C++.
I recommend using a pre-packaged MinGW that includes some common APIs like Boost, SDL etc: http://nuwen.net/mingw.html
If I remember correctly, the only thing you must do to get it working is to modify Windows's PATH environment variable.
edit: OpenAL is not included in this package.
Here are some instructions to have a MinGW setup that I used to build Octave modules.
I have switched to using the build environment for msysgit. Just download the netinstall file and it will setup GCC, Make, etc. along with Git.
This question already has answers here:
C++ cross-compiler from Windows to Linux [closed]
(5 answers)
Closed 9 years ago.
I need to write a relatively simple command line C++ program to be run a Linux environment. However, I would like to code as well as compile this on Windows. The reason I don't want to port it to Linux is because it requires MySQL interactions, and that would require some messy porting (IMO). It does not have to run on Windows; I just want to compile it on Windows because I want to use my preferred IDE's.
I've looked up on Cygwin for this task, but I haven't been able to find any documentation to do what I'm trying to do.
(I'm assuming "..don't want to port it to Linux.." is a typo for "..from Linux" and that you want the code to run in Linux as you said in your first sentence. This means cygwin or mingw would only be used as cross compilers and aren't going to be very useful.)
This program already builds and works (or mostly works) on Linux, right? No reason to change that. Use your preferred editor (probably the one in your IDE) to edit the files and then just run the build system (probably make) in a Linux system (possibly in a VM). Export the files using a samba share (especially easy from a VM) so you can edit and automatically save remotely.
Note that you seem fine ditching every other feature of your IDE (debugger and compiler, mainly) and just using the editor part anyway.
Ah, are you not starting from any existing project and want to write this from scratch? If so, porting doesn't make any sense. You want to write cross-platform code. (Cross-platform or "portable code" being related to, but different than, the act of "porting code" from one platform to another.)
The code is then both "Windows code" and "Linux code" at the same time, and you can use any compiler on Windows that can accept the code. Usually this happens by you sticking to standard libraries and other portable libraries, or writing shims for non-portable libraries to give them a portable interface, with the compiler supporting the C++ Standard.
You can use your preferred IDE's compiler and debugger in this case, and don't need cygwin or mingw. (Unless they're used by your preferred IDE. :P)
MinGW + MSYS
MinGW provides the functionality, MSYS gives a linux-like command prompt to use MinGW at.
When you get cygwin, install the C++ compiler/build tools, e.g., gcc, g++, make, autotools, etc. I think these are all you need, but I may be wrong. In any case the Cygwin installer is easy to use, and should bring in any dependencies.
Once you have these setup, you can configure your IDE to use g++ as your default compiler. You also need to set your library and include paths correctly such that they point to the relative /usr/include and /usr/lib directories under $CYGWIN (%CYGWIN%).
(Your other option is to use MinGW set of tools, in which case the IDE setup is more or less the same.)
Install cygwin (tutorial) and you'll have an EXE that gives you the command line prompt you're looking for.
The Cygwin installer should have an option for installing whatever compiler you're looking for (gcc?).
Here's another relevant tutorial.