So I just got into using VS Code. I am currently working with C++ and I am using Mingw as my compiler. So far I have been using the terminal at the bottom of VS Code to compile and run like this:
g++ program.cpp then doing ./program.exe
The process of using the terminal at the bottom is time consuming especially when I need to compile and run code frequently. This is also annoying when creating classes when you have to compile multiple files into .o extensions etc.
Can anyone help with this process? Am I doing something wrong, should there be an easier way? Maybe a makefile?
Thanks!
If you want to compile and run C++ code in visual studio code(Vs-code) in windows. This include following steps.
Download Visual studio code.
Go on Add extension Type C++ and install "C/C++" by Microsoft.
Go to Visual Code studio docs for "C++" OR https://code.visualstudio.com/docs/languages/cpp
Install MinGW-x64 vis MSYS2 website and run this on shell "pacman -S --needed base-devel mingw-w64-x86_64-toolchain"
Then go to windows setting and look for Edit environment variables for your account. Then in advance settings >> Environment Variable.
In "system variable" choose path and edit it and add a new path.
You can find a new path in your directory where you have installed the MinGW-x64. you might find it in C:\msys64\mingw64\bin. or where ever you have installed it.
When you have added the new path then go to any shell/cmd and Type g++ --version
if you get the version then you have succeded.
If you find something like command not recognized then please check where you have done wrong or skipped any step.
Otherwise startover.
thanks--
I'm fairly far in a project using GTKmm atm, and I'm trying to add in some code a friend of mine have been working on. However I'm getting this error:
error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be
enabled with the -std=c++11 or -std=gnu++11 compiler options
However I can't find anywhere that will actually let me add these compiler options.
Adding it to Build -> Configure Project only yields a:
Error: unrecognized option 'std=c++11'.
Anyone more familiar with this IDE who might be able to help?
Note that the commandline options start with a '-'. So the option is -std=c++11 (See man gcc).
Adding an option in Build -> Configure Project must be done like this
CXXFLAGS='-std=c++11'
You can also go to Project | Project options, then select your target in the top box. An options should appear 'More options'. Click on that, and you can enter -std=c++11 in the option field you want to use (probably Compiler flags).
It works here, but I have gcc version 4.8.x
I'm trying to debug a c++ project (existing code) in Netbeans.
I can run the code fine by hitting the Run button, but debugging isn't working for some reason. I've seen a lot of suggestions telling that the -g flag needs to be added to the gcc compiler options in Netbeans.
From what I understand this used to be done through the *Aditional options" field in the project properties. But this field doesn't exist anymore in Netbeans 8.
Where can I add the -g flag to the gcc compiler options in Netbeans 8?
If it's a normal C++ Application project, then your NetBeans pulldown menu (to the left of the Build Project button - an icon with hammer) should have at least three lines - Debug, Release and Customize. Choose the Debug configuration to build the project, then the -g option will be added automatically.
Facing variety of issues with the latest Eclipse Juno in Ubuntu 12.04, after switching from Indigo.
I have set below flags in:
Project -> Properties -> C/C++ Build -> Settings -> Tool Settings -> Cross G++ compiler
-> Miscellaneous: -std=c++11
-> Preprocessor: __GXX_EXPERIMENTAL_CXX0X__ (also set in C/C++ General -> Paths and Symbols)
Presently, I am compiling the code which was compiling fine with C++03 in Indigo. After changing to C++11, I did get some errors which were probably due to g++ extension, and I have fixed them.
Now here are the problems which I want to fix:
If I switch back to normal C++ compilation, then I receive single error:
This file requires compiler and library support for the \ ISO C++
2011 standard. This support is currently experimental, and must be \
enabled with the -std=c++11 or -std=gnu++11 compiler options. from
the file c++0x_warning.h. The error doesn't go away even with
clean build or restarting the eclipse.
Debugging doesn't work as expected. The execution does stop at given
break points, but when I hover my mouse on the variables, it doesn't
show any values. In Indigo it used to show it. Did lot of trials and
errors in various settings of Eclipse, but no luck. Also checked,
Window -> Preferences -> C/C++ -> Hovers, but unable to change
anything there.
Including <unrodered_map> works fine, but if
std::unordered_map<> is used then it starts giving error. For now,
I am least concerned with this issue among others.
If anyone can suggest a link or method to do the effective debugging with Eclipse (Juno), then it will be of great help for future visitors as well.
Note: I have referred several threads in SO, but none of them were helpful:
Eclipse CDT C++11/C++0x support
Cannot set Eclipse Juno C++ with std=c++11
Eclipse CDT Juno - Toolchain issue
First of all, I started off with a fresh installation of the whole thing, and as something for future reference, I want to show how to install and use GCC with Eclipse from scratch.
Firstly go to the Ubuntu Software Center, and download the latest versions of GCC, which is GCC 4.8. Now, you might encounter problems doing this, so I suggest that you type in gcc-4.8 when trying to find the software. Same thing with g++, you type in g++4.8 to get what you want. Make sure you have the right versions. Due to the open source nature of Linux, there tend to be lots of problems involving versions.
-> : press enter
Now, open up your terminal, and enter the following:
sudo su - -> this will give you special root privileges.
Now it will ask for your password, enter that ->
!Warning, make no mistakes in this part, since root can do a lot of damage!
Now change your directory, enter cd /usr/bin ->
Type ls -l gcc* g++* cpp* ->
This will show you the symbolic links available to those data types
Type ln -s g++-4.8 g++->
Type rm cpp gcc ->
ln -s gcc-4.8 gcc ->
ln -s cpp-4.8 cpp ->
Now CTRL + D, twice, and that will move you out of the terminal.
Now, open up eclipse. Go to Preferences>New CDT Wizard(or something like that)
Make sure that Linux GCC is selected. Make press the Make Toochains preferred.
Now, when you open up a project, make sure you go to the project properties, and you do the following:
C/C++ Build > Settings > Misc. > Under other flages add this -std=c++11.
Same thing with GCC C compiler, but this time, you add -std=gnu11
That should set everything up. Don't use Cross GCC, it has always given me problems.
I have gpp installed in my Windows 7 (32 bit) as shown in the picture.
PATH variable gas g++
"%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\cygnus\cygwin-b20\H-i586-cygwin32\bin\g++"
Still eclipse shows the error:
"Program "g++" not found in PATH".
How can this be resolved?
Today I have bumped into this problem and solved it in the following way. I pressed "Reset defaults" button everywhere I could find it in Eclipse settings (for example, Preferences/C++/Build/Settings/Discovery). After that the error disappeared and the code compiled successfully.
This is how I got rid of it:
Install the MinGW.
Select all files in the Basic Setup and select apply the changes.
Select new C++ Project You will be able to see "MinGW GCC" in the toolchain section select the same and create project.
You need a gcc, g++ compiler toolchain (on your windows machine) for the eclipse which you have manually downloaded,
One of the options can be done implicit via cygwin installation(by selecting proper development packages for gcc, g++) and then add the location of the compiled gcc ,g++ package like C:\cygwin\etc\alternatives to the PATH variable for windows environment.
After this open eclipse and go to Project->properties->C/C++ Tool Chain Editor and add replace default GNU C++ compiler and GNU C Compiler with Cygwin C++ compiler and Cygwin C compiler and rebuild the project. The errors related to gcc, g++ PATH not found will now be gone.
You need:
C:\cygnus\cygwin-b20\H-i586-cygwin32\bin
in the PATH.
and not
C:\cygnus\cygwin-b20\H-i586-cygwin32\bin\g++
as you wrote.
I got the same problem with mingw-64 (x86_64-4.9.1-release-posix-seh-rt_v3-rev1), Eclipse Luna 4.4.1 and CDT 8.5.0.201409172108, using Windows 7.
I solved this problem by putting the following two environment variables under
Window -> Preferences -> C/C++ -> Build-> Environment
name: MINGW_HOME value: (mingw installation directory without "\bin")
name: MSYS_HOME value: (msys installation directory without "\bin")
You can check
Window -> Preferences -> C/C++ -> Build -> Settings -> Discovery -> CDT GCC
Built-in Compiler Settings MinGW [ Shared ]
, if it doesn't complain "Toolchain MinGW GCC is not detected on this system" then you're all set.
I had the same problem, the only solution that worked for me was this:
Open command-line and check whether "g++" actually executes the compiler
If (1) works, uncheck Project->Build automatically in Eclipse
Clean project
Build project
I had the same problem: Eclipse couldn't find (g++) and (gcc) in PATH even they were accessible from command-line. I was also sure they are pointed by PATH correctly.
I have just deleted the (.metadata) folder from Eclipse's Workspace as a mean to reset it and this worked for me.
The PATH is locate at Project Properties > C/C++ Build > Environment (see screenshot below).
For your reference, I am using MinGW, I got the same error before I got the MSYS install. Later I found out that I also need MSYS to be install because the make.exe wasn't come with MinGW. (I don't this error was cause be MSYS.)
After MSYS is installed, add MSYS and MinGW path into environment variable, restart Eclipse. Remember to rebuild your project in order to rectify the error. If error still persist after restart, recreate the workspace. At least this has solved the problem on my site, hopes this help on you too.
Good luck!
I had a similar problem. The error is raised, but the code is compiled and linked. The error was caused by the Error Parser using a different configuration than the one that is compiled.
The error parser configuration was only valid for the Linux configuration of my software. My active configuration was set for MinGW and Windows.
Solution:
In Elipse under Windows->Preferences->C/C++->Indexer set Build Configuration for the indexer to Use active build configuration.
Clean and rebuild, otherwise the old errors will remain visible
Maybe it has nothing to do here, but it could be useful for someone.
I installed jdk on: D:\Program Files\Java\jdk1.7.0_06\bin
So I added it to %PATH% variable and checked it on cmd and everything was ok, but Eclipse kept showing me that error.
I used quotation marks on %PATH% so it reads something like:
%SYSTEMROOT%\System32;"D:\Program Files\Java\jdk1.7.0_06\bin"
and problem solved.
I had similar problem and I solved it by:
Installing g++ The GNU C++ compiler using Ubuntu Software Center
Changing in: Window -> Preferences -> C/C++ -> Build -> Settings -> Discovery -> CDT GCC Build in Complier Settings [Shared]
from: ${COMMAND} -E -P -v -dD "${INPUTS}"
to: /usr/bin/${COMMAND} -E -P -v -dD "${INPUTS}"
I hope it helps.
I had the same problem in Sublime..
Right click on my computer
Advanced system settings
Environment variables
in system variables, change path to location of '...\MinGW\bin'
Example: D:\work\sublime\MinGW\bin
For me it got fixed with:
Go to:
Window -> Preferences -> C/C++ -> Build -> Environment
Then press "Add..."
Name: MINGW_HOME
Value: C:\MinGW (yours might be different if you choose a custom path)
Hit "Apply and Close"
Now, it shoud work if you did everything correctly
i think cgywin might not work for you as you can only compile your code in Win7 if you fire up the command prompt; you need to use MinGW compiler toolset instead. After you have install your compiler, go to Properties->C/C++ Build->Tool Chain Editor -> Change your current toolchain to MinGW GCC.
WINDOWS 7
If there is anyone new reading this, make sure to simply try a clean install of mingw before any of this. It will save you sooooo much time if that is your problem.
I opened up wingw installer, selected every program for removal, apply changes (under installation tab, upper left corner), closed out, went back in and installed every file (in "Basic Setup" section) availible. after that eclipse worked fine using "MinGW GCC" toolchain when starting a new C++ project.
I hope this works for someone else.
If not, I would do a reinstall of JDK (Java Developer's Kit) and ECLIPSE as well. I have a 64bit system but I could only get the 32bit versions of Eclipse and JDK to work together.
In my case, I didnt mark for instalation the mingw32-gcc-g++ package in the installation manager, that's why eclipse didn't know it.
Needed to go to the instalation manager, mark it (in basic setup tab) and update catalogue
If you have your PATH setup and you can see g++ --version via the command line, then try to delete the project and create a new c++ project.
So the reset defaults might work but I think it has to update the PATH if it wasn't added before.
Had this problem on windows 10, eclipse Neon Release (4.6.0) and MSYS2 installed.
Eclipse kept complaining that "Program 'g++' not found in PATH” and "Program 'gcc' not found in PATH”, yet it was compiling and running my C++ code.
From the command prompt, I could run g++.
Solution was to define the C++ Environmental variable for eclipse called 'PATH' to point to windows variable called 'path' also $(Path).
Menus: Preferences>>C/C++>>Build>>Environment
Looks like eclipse is case sensitive with the name of this environmental, while windows doesn't care about the case.
First Install MinGW or other C/C++ compiler as it's required by Eclipse C++.
Use https://sourceforge.net/projects/mingw-w64/
as unbelievably the download.cnet.com's version has malware attached.
Back to Eclipse.
Now in all those path settings that the Eclipse Help manual talks about INSTEAD of typing the path, Select Variables and
**MINGW_HOME**
and do so for all instances which would ask for the compiler's path.
First would be to click Preferences of the whatever project and C/C++ General then Paths and Symbols and add the
**MINGW_HOME** to those paths of for the compiler.
Next simply add the home directory to the Build Variables under the C++/C Build
Build Variables Screen Capture
All the tips did not work for me using the Gaisler Tools for GR712RC Installation for OS RTEMS.
I'm using the Eclipse Kepler.
The simple way was making a copy of sparc-rtems-gcc.exe to gcc.exe, and sparc-rtems-g++.exe to g++.exe, in the C:\opt\rtems-4.10-mingw\bin directory.
The reason is that eclipse cannot find your gcc or g++ environment variable path.
You might have tried to run c or c++ or fortran but eclipse cannot find out the compiler.
So, add the path in your environment variable.
Windows -> Search -environment variables -> click on environmental variables at bottom.
Click on path ->edit -> new -> your variable path
Path should be entire, for example:
C:\Users\mahidhai\cygwin64\usr\sbin
Make sure that the variable is permanently stored. It is not erased after you close the environment variables GUI.
Sometimes you might find it difficult to add a path variable.
Make sure windows is updated.
Even if Windows is updated and you have problems, directly go to the registry and navigate to the below.
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
Add your path here. Remove any unnecessary repetitions of path variables.
Note:
You need to add your path variables in system environment variables -path
enter image description hereIf you just want to run C program but meet this error, it might mean that MinGw c++ compiler has not been installed even if "C:\MinGW\bin" has already been added to Windows Path variable.
Solution:
Run "mingw-get-setup.exe" to open MinGW Installation Manager
Open All Packages->MinGw->MinGW Base System->MinGW Compiler Suite
Select the following compilers to install:
. mingw32-gcc-g++
. mingw32-gcc-v3-core
. mingw32-gcc-vc-g++
Click Installation->Apply Changes to apply the above changes
Wait for the installation finishing(There might be some errors, just ignore them).
Restart Eclipse.
Done.
It Worked in my environment.
Hope it works in your case.