Integration of other C + + compilers into VC2005

Source: Internet
Author: User
Tags command line contains reference versions

In Visual C + + 2005, how do I invoke another compiler to compile a CPP file? In other words, how do you integrate other compilers into the VC2005 IDE?

Compilers like IIC are automatically integrated after installation, and to integrate with other compilers you have to do it yourself. Here's an easy way to do this.

In addition, you cannot compile a single. cpp file in the IDE of VC2005 unless you put it in the project. However, we can implement the compiled single file by invoking the external tool.

The way to add cl.exe to external tools is not introduced here, we refer to the following add GCC method, and then consult the Cl.exe parameter description, you can try to add in.

The following example describes how to compile a CPP file by calling g++. If you are compiling a single. c file, you can use GCC to do the same.

First get the Windows version of the GNU C + + Compiler (g++). You can get g++ for Windows by installing Cygwin or MinGW.

Take MinGW as an example, we can download dev C + +, Dev C + + is currently the latest version of 4.9.9.2. Installing Dev C + + also installs the MinGW, which contains g++ 3.4.2,

Suppose Dev C + + is installed in the D:\DEV-CPP directory.

Below we click on the VC2005 menu (Tools)-> External tool (External tool)-> Add.

Separate fill in:

Title: GNU C + + Compiler

Commands (command): D:\dev-cpp\bin\g++.exe

Parameters (Arguments):-wall-o $ (itemfilename) $ (itemfilename) $ (itemext)-time

Initial directory (Initial directory): $ (Itemdir)

Then tick the "Use Output Window" below.

Description: If you have added the D:\Dev-Cpp\bin\ directory to the System environment variable, the command is specified as G++.exe. Cygwin the same.

These parameters are just a reference. You can check the VC compiler macros to set the parameters you need.

Simply incidentally, add the reference parameter settings for the digital Mars C + + compiler:

Title: Digital Mars

Commands (command): C:\dm\bin\dmc.exe

Parameters (Arguments): $ (itemfilename) $ (itemfilename) $ (itemext)

Initial directory (Initial directory): $ (Itemdir)

Below, switch to the file of main function, "GNU C + + Compiler" under the Tools menu to start compiling.

Note that g++ is compiled at this point is a pure C + + program, for the inclusion of int _tmain (int argc, _tchar* argv[]) This kind of VC-specific C + + program can not be compiled by nature.

If the compilation is not wrong, there is no Output window for earlier versions of g++.

For newer versions of g++, information similar to the following is output:

# Cc1plus 0.67 0.22
# as 0.05 0.01
# Collect2 0.36 0.19

This is the CPU time that each child process occupies during the compilation of the-time report.

Of course, you can also change the compilation parameters so that the Output window outputs other compilation information.

We can also implement the ability to run g++ generated programs by adding external tools. The steps are as follows:

Click on the VC2005 menu "Tools"-> external tools (External tools)-> Add.

Separate fill in:

Title: Run as C + + application

Commands (command):%systemroot%\system32\cmd.exe

Parameters (Arguments):/C $ (itemfilename). exe

Initial directory (Initial directory): $ (Itemdir)

Do not tick the "Use Output Window" below and "close off when exiting."

Note: CPP files must be placed in the project, g++ generated by the program can be run!

In addition, a program compiled with MinGW g++ cannot run on a Windows system that does not have MinGW installed. Because it relies on the MinGW library.

Even the WIN32 console application, compiled with VC2005 without a precompiled header, is an empty environment, so that the compiled executable file is not running on any machine.

Let's talk about how to set up shortcut keys.

Click "Tools-> Customization" in the menu,

Click on the "keyboard" in the lower right corner,

Click the text box below the "Press shortcut" button,

Press Shift + Ctrl + F7, if the shortcut has been assigned to another command, replace one.

In the show command contains, fill in the tools. External command 6, and then click the "Assign" button.

Click OK, and then click Close.

This assigns the GNU C + + Compiler A shortcut key shift + Ctrl + F7

Note that just now, in the case of the GNU C + + Compiler located in item 6th of the External Tools menu, fill in the "Show command contains" tool. External command 6 "!

Similarly, we can assign a shortcut key to the Run as C + + application.

Let's talk about how to assign a tool bar.

Click "Tools-> Customization" On the menu and click on the "Toolbars" tab.

Click "New",

In the toolbar name, fill in "g++",

Switch to the Command tab.

Click "Tools" in "categories",

In the command on the right, drag "external command 6" onto the g++ toolbar you just created.

Do not close the Customize dialog box first.

Below, click the GNU C + + Compiler button on the g++ tool bar

Click the Modify Selection button in the Customize dialog box to set properties such as the name and text of the button in the sidebar.

The Run as C + + application can also be placed in the g++ sidebar in this way.

With such integration, it is convenient for beginners to learn pure C + +. I think that for the beginners of standard C + +, it is not possible to think of compiling with VC. It is necessary to compile the check once with g++. Now all we need to do is click on the shortcut key to see if the code can be compiled with other compilers, such as g++, and not switch to the command line to recompile the program.

However, if you want to output g++ output to the error list, or the VC IDE to debug the g++ generated program, it should be absolutely impossible. In fact, there is no need. Personally think.

Feeling g++ error is more intelligent than VC, which helps us to quickly find the root of the problem.

If you are interested, you can also add Make.exe to VC2005 's external tools to achieve the goal of compiling the entire project. Of course, there are makefile in the works.

GDB.exe can also be integrated in, but don't forget that the parameter (Arguments) should be-g-wall-o $ (itemfilename) $ (itemfilename) $ (itemext)-time, where parameter-G generates debugging information. The GNU debugger can take advantage of this information.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.