How to use Microsoft C++ compiler with NetBeans? - c++

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.

Related

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

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.

Setup C++ on Visual Studio Code [duplicate]

I am programming in C in Visual Studio Code, but I can't compile, as VSC only offers three compilers built in - Node.js, C# Mono, and Extension development. After a little bit of digging I came across the Visual Studio Marketplace. This seemed like the right sort of thing, but only four uncommon languages were there.
I can only assume that C debugging support is built in, I just can't find it or I am going the wrong way about doing it. I attempted to create a new launch.json (the manifest that seems to hold the compiling/debugging settings for each file) and manually entering the GCC binaries that I have, but that didn't end up working. I'm currently stuck manually compiling the C source file I am working on through command prompt.
Would really help if someone could point me in the right direction on what to do.
tl;dr - Help from anyone debugging C in Visual Studio Code
Windows 8, if that matters
Cheers!
Caution
A friendly reminder: The following tutorial is for Linux user instead of Windows
Tutorial
If you want to debug your c++ code with GDB
You can read this ( Debugging your code ) article from Visual Studio Code official website.
Step 1: Compilation
You need to set up task.json for compilation of your cpp file
or simply type in the following command in the command window
g++ -g file.cpp -o file.exe
to generate a debuggable .exe file
Step 2: Set up the launch.json file
To enable debugging, you will need to generate a launch.json file
follow the launch.json example or google others
Step 3: Press (Ctrl+F5) to start compiling
this launch.json file will launch the configuration when you press the shortcut (Ctrl+F5)
Enjoy it!
ps. For those who want to set up tasks.json, you can read this from vscode official (-> TypeScript Hello World)
Press Ctrl + Shift + P to pull up the Command Pallette, and Type ext install cpptools. It will install everything you need to debug C and C++.
Debugging in VS code is very complete, but if you just need to compile and run:
https://code.visualstudio.com/docs/languages/cpp
Look in the debugging section, and it will explain everything.
There is a much easier way to compile and run C code using GCC, no configuration needed:
Install the Code Runner Extension
Open your C code file in Text Editor, then use shortcut Ctrl+Alt+N, or press F1 and then select/type Run Code, or right click the Text Editor and then click Run Code in context menu, the code will be compiled and run, and the output will be shown in the Output Window.
Moreover you could update the config in settings.json using different C compilers as you want, the default config for C is as below:
"code-runner.executorMap": {
"c": "gcc $fullFileName && ./a.out"
}
For Windows:
Install MinGW or Dev C++
Open Environment Variables
In System Variable select Path -> Edit -> New
Copy this C:\Program Files (x86)\Dev-Cpp\MinGW64\bin to the New window.
(If you have MinGW installed copy its /bin path).
To check if you have added it successfully: Open CMD -> Type "gcc" and it should return:
gcc: fatal error: no input files compilation terminated.
Install C/C++ for Visual Studio Code && C/C++ Compile Run || Code Runner
If you installed only C/C++ Compile Run extension you can compile your program using F6/F7
If you installed the second extension you can compile your program using the button in the top bar.
Screenshot: Hello World compiled in VS Code
Just wanted to add that if you want to debug stuff, you should compile with debug information before you debug, otherwise the debugger won't work. So, in g++ you need to do g++ -g source.cpp. The -g flag means that the compiler will insert debugging information into your executable, so that you can run gdb on it.
You need to install C compiler, C/C++ extension, configure launch.json and tasks.json to be able to debug C code.
This article would guide you how to do it: https://medium.com/#jerrygoyal/run-debug-intellisense-c-c-in-vscode-within-5-minutes-3ed956e059d6
EDIT: As of ~March 2016, Microsoft offers a C/C++ extension for Visual Studio Code and therefor the answer I originally gave is no longer valid.
Visual Studio Code doesn't support C/C++ very well. As such it doesn't >naturally support gcc or gdb within the Visual Studio Code application.
The most it will do is syntax highlighting, the advanced features like >intellisense aren't supported with C. You can still compile and debug code >that you wrote in VSC, but you'll need to do that outside the program itself.

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 Compile C++ Code Using Vim on Windows?

First, I install Vim (Text Editor) in Typical type, on this Windows 7 laptop. And this user that I'm using is an administrator on this computer but couldn't open file in “Program Files” location for writing with Vim. So I change my :cd current directory to my $HOME.
Note: I already have installed Visual Studio Express for Windows Desktop. I just want learn how to use this.
Can I compile C++ code using Vim in Typical type alone on Windows?
If it's possible, then what's the process for compiling C++ code?
I have hello.cpp file but I can't compile it. I already use :comp gcc and :make and the output is: 'make' is not recognized as an internal or external command,
But when I use :comp msvc and :make, the output is: 'nmake' is not recognized as an internal or external command,
Now, what should I do? If it's not possible using Vim alone, how can I compile using Vim with the compiler on my VS Express for Desktop?
VIM is a great text editing tool,its like an awesome version of notepad.But it's not a compiler,neither has a build in compiler of itself.So In order to compile the program you'll need a separate compiler installed,like You can use MinGW.
See This :
How to use MinGW make with Vim on Windows
Vim is just an editor tool. To compile a program you need a compiler tool chain. The one that Visual Studio use is Microsoft Visual Studio C++ Compiler, so you could use it. Or install and use gcc.
The make file that you are generating is used by make utility to actually compile the code for you. There is a Windows version of this tool.
However I would suggest you to perform minimum steps to compile a c++ program manually for better understanding of the process:
Create source .cpp file -> Create object file with a compiler-> create executable with a linker
Good step-by step instructions for Visual c++ here
If you prefer to use gcc, these are good links how to install and use it on Windows.

Using Visual Studio 6 C++ compiler from within Emacs

I'm just getting started with c++ development and I would like to use emacs to write the code and then compile and run it from within emacs using the visual studio 6 compiler. I have already googled around a bit but just can't seem to find an explanation of how this is done.
Any pointers?
Thanks for your help,
joerg
I have done this as a matter of course over the past few years. There are two ways to do this:
In the older versions of VS (including VS 6.0), there is a button to export the nmake file for the project. I do this on occasion and then use nmake to compile. I have
(setq compile-command "nmake debug ")
in my .xemace/init.el for this. You have to add the name of the nmake file, and nmake.exe has to be in your path. (BTW, I modified compilation-error-regexp-alist-alist to help moving through the errors. Let me know if you want this as well.)
Newer versions of VS do not have the button to export the nmake file. For these I call devenv.com. In this case I have
(setq compile-command "devenv.com /build Debug ")
in my .xemacs/init.el. You have to add the name of the .sln file. Although I did not do this with VS 6.0, I believe that it may work as well.
I am not sure if you would consider merely swapping the text editor inside of Visual Studio with Emacs, but here is a sf.net project which does just that.
http://sourceforge.net/projects/visemacs/
Checkout http://www.kuro5hin.org/story/2003/4/1/21741/10470
As a followup to Andrew Stein's answer, to do a command line build on Visual Studio 6 without using nmake, use the syntax:
msdev wspname.dsw /make "project - Win32 Debug"
Visual Studio is an IDE
It uses the cl.exe compiler underneath.
We use emacs with GNU make (gmake), which is wrapped with our own gmake wrapper executable and it works very well.
Just set up simple a keybinding to invoke cl.exe on .c/.cpp files that you are compiling to build your .obj files. We have one keybinding for initializing a compile in a folder, which will make all .obj files that are not up to date, but this is purely handled by GNU make.
We also have other keybindings, e.g. for linking the executable and starting it etc.
A bit off topic, but why are you using visual studio 6? The compilers (as well as stripped down IDEs) for the current version of visual studio are available for free from Microsoft.
In either case, you can invoke the compiler from the commandline so it should be as simple as setting up a makefile.
If you just want to set up a single file to compile then put this at the top of your file...
// -*- compile-command:"g++ test.cpp -g -lwinmm -o test.exe"; -*-
See my blog post on this
Of course you need to adjust to use CL.EXE and choose the appropriate arguments.
For launching make it's a bit trickier since you have to run make as if you were in the parent source directory, when you are editing a file further down the hierarchy.
The only way I know of to do that is to put this at the top of every file ...
// -*- compile-command:"nmake"; default-directory:"c:/projectroot/"; -*-