How can I change build tools for projects in VS Code? - c++

I want to build a C++ code but it errors. When I check the error message it's related with .NET. I have C# extensions but this isn't C# and I want to change this to g++ for C++ projects. I have g++ installed and added to path however I don't know how can I configure it to build with that for C++ codes.
Edit: I marked the answer as a solution but I also found an easier way for me:
https://code.visualstudio.com/docs/cpp/config-msvc
cl.exe basically.

One option (probably not the one you want to) is to build it from integrated terminal.
You can download c/c++ extension along with the cmake tools extension to have buttons for build/run configuration.

Related

How to compile and run C++ code in VS Code easily?

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--

VSCode c++ configuring for vc toolchain

I'm trying to start a work in vscode , latest C++ plugin version supports ms debugger, so as I'm mostly working under windows it was a signal to try this.
c++ tools plugin from MS and cmake tools were installed.
my test project was however not built . the problem is clear , but I need an advice from experienced vscode users how to solve this right.
cmake doesn't see vc compiler.
(after using QtCreator) I expected that vscode could detect vc installation... however that's not so. ok, I have a two ways:
fill environment variables INCLUDE/LIB/PATH with a headers, libs and binaries
just run vcvarsall.bat x64
Second way is a simple and reliable. so final question is:
how to run .bat at the begining of vscode start?
(I don't mean write another bat/cmd, prepare the environment and run vscode inside the same script after that)
Although the question is fairly old, I'll try to give a useful answer, in case others stumble across, just like I did.
I believe what you are trying to achieve is not possible. Code inherits the environment it was started with. If you did not launch it from a developer command prompt, you will not be able build and debug. (Building might be possible if every task first starts the vcvarsall.bat, but that slows things down by a lot. Debugging I think will still not work.)
If you are willing to, you can check out vector-of-bools CMake Tools extension which does build automation as well as automatic MSVC detection. It builds using CMake (thus you need to write your build scripts using CMake), but it will take care of building just by pressing F7, like what most VS users are familiar with.

LLVM 3.8: implementing a pass with ad IDE (Xcode)

I'm a newbie in both LLVM developing and cpp.
I wanted to ask if there was a way to develop a pass for LLVM in Xcode having all the typical features available in an IDE like autocomplete and syntax code highlighting.
Right now I am just writing c++ code, checking everything I need on the documentation, but, as you can imagine, this is really slowing me down and it's really error prone...
Don't know if this can help, but my LLVM folder is structured this way:
"llvm_3.8_source/" root folder of llvm3.8 source files
"llvm_3.8_source/build" root folder of my llvm3.8 build
Thanks
Yes, it is possible.
LLVM uses CMake as a build-system generator. CMake supports such things as old good makefiles, ninja, xcode, and visual studio.
You can simply create Xcode-project using the following commands from terminal:
cd llvm_build
cmake -G Xcode path/to/llvm/sources
open LLVM.xcodeproj
First you will see lots of errors and 'red' marks. It's because some parts of LLVM sources are generated during compilation.
All files will be generated as soon as you attempt to build project first time and all the 'red' marks will gone.
You can read this article to get a bit more info on the topic:
Getting started with LLVM/Clang on OS X

Visual Studio custom build definitions for CLI built embedded C++

I have a build engine from ARM, called yotta. I have been working with the command line, where with the following commands, I can build projects and produce outputs.
$ yt target bbc-microbit-gcc
$ yt build
The compiled file is then accessible from build/bbc-microbit-gcc/source/Project-name-combined.hex
Is it possible to automate this CLI and build it into Visual Studio as a build definition? I know in Visual Studio Team Services / Team Foundation Server), you can define build steps using the command line, what is the local equivalent.
I am using Visual Studio Enterprise 2015. Any nudge in the right direction would be much appreciated.
EDIT:
I have seen the GCC4mbed project, but it would be good to use the new yotta command line build to do this. As far as VS is concerned is a command line tool which adds a built version of the project to a directory, a build tool? If so, then I know I can just follow the guides to add a custom build tool to VS however, it strikes me that VS might need a build tool to be in a certain standard to make intellisense etc work. In which case I might need to create a build tool on top of the existing yotta work and specify this to VS? Ideas would be muuch appreciated.
did you try to use cmake generators option which yotta provides (as it uses CMake)?
yotta build --help
-G CMAKE_GENERATOR, --cmake-generator CMAKE_GENERATOR
CMake generator to use (defaults to Ninja). You can use this to generate IDE project files instead, see cmake --help
The ideal solution which implemented partially as VS debug engine is still under development, just recently allowed gdb extensions. The tool on top of yotta for debugging is called Valinor (which is using progen: https://github.com/project-generator/project_generator).
Progen supports visual studio gdb (its very limited at the moment as explained later). I was able to use yotta debug with visual studio, but not without hacks (dated back in November-December 2015). The idea was to have a visual studio project with gdb setup and custom build commands (make,cmake or yotta) (in our case would be pyOCD settings, could be openOCD or jlinkGDB, and built environment for yotta).
As I recall, you commented on the issue on https://github.com/project-generator/project_generator/issues/98, and I haven't heard back from you. The problems I had I recall was I could not start gdb server (I had to do it manually), I could not make it to pass arguments to gdb (like load/reset/halt when starting the session).
I'll update my VS plugins and check if there were any updates in gdb plugins, I was told there should be.
I appreciate any help, either for progen or valinor to make this available for users.

How to use Microsoft C++ compiler with NetBeans?

I was wondering whether it's possible to use Microsoft's C++ compiler and linker with NetBeans IDE?
If so, what's the best way of doing it.
P.S. I'm not interested in Mingw.
EDIT: Is it possible to get NetBeans to do error parsing (so that I can click on error and have NetBeans open the right file), intellisense, etc? I know NetBeans can work with g++ make files. Why not with nmake?
I am currently writing a plugin/toolchain to use Visual C++ on Netbeans.
You can find the project called VCC4N on source forge or on NetBeans plugins.
To be honest, I always do my spare time coding inside an ide (e.g. code::blocks, monodevelop, anjuta) or an editor (virtually always scite), and the compiling I do in a terminal via a makefile (handwritten, cmake, automake).
This isn't really a problem w.r.t. time to compile: F7 (or some other of the F keys) vs. (alt+tab, up, enter), where (alt+tab) and (up) are pressed nearly at the same time, but I get the great benefit of having up to full screen compiler reports, and often I am anyways testing my programs in a terminal. Also, it makes my code more independent of the IDE (ever tried to get a makefile from code::blocks for distribution purposes?).
The visual studio compiler is called cl.exe and the linker is link.exe. These are present in particular visual studio directories. From inside visual studio > project properties > C++ > Command Line, or by disabling "Suppress Banner" option there, you can find the command that visual studio runs. You can call these command lines from inside netbeans.
Getting all the file names into the list to compile may be more tricky. You need a build system for this. You can try to use the same mechanism that visual studio uses, but sorry my knowledge fails there. Alternatively, you can use CMake or some other build system. Then, whenever you add/delete a source file, you would have to update the CMakelist.txt to be able to compile.
You can get syntax highlighting, code graphing etc from netbeans without having a compiler installed I think (not certain, you may need cygwin or mingw for parsing). What you must do is create at least an empty makefile. If you want to use Microsoft's compiler then you either need to:
a) Write the makefile yourself to compile eveything using cl
b) Call on msdev from the makefile with the project name and it will compile everything
b) Call something like scons from the makefile to compile everything
I use netbeans to develop cross platform software, at this time though, I don't actually run the builds from netbeans.