Linux builds C++ development and debugging environment

Install g++

Linux compiles C++ program must install g++ compiler. Use yum to install here. First switch to the root account, su-root and enter the password.
Linux builds C++ development and debugging environment
Execute yum install gcc-c++ (note that it is not yum install g++), and an error is reported.
Linux builds C++ development and debugging environment
The error is reported because yum needs to configure the correct server address. The server provides the yum installation package, which is also called yum source. The configuration file for configuring the yum source is in the /etc/yum.repos.d/ directory, you can see that the system comes with two files.
Linux builds C++ development and debugging environment
cat file name, it will print all the contents of the file. You can see that the two files are either not configured, or the address is not accessible.
You can download the yum source address provided by major domestic manufacturers from the Internet. I downloaded the source address file CentOS6-Base-163.repo provided by 163 NetEase here.
Use ftp upload tool CentOS6-Base-163.repo when the newspaper made a mistake, because I landed ftp not using the root account, upload files and directories that only root has access to
Linux builds C++ development and debugging environment
use root landing ftp tool, successfully uploaded
Linux builds C++ development and debugging environment
Linux builds C++ development and debugging environment
to try now yum command
Linux builds C++ development and debugging environment
this time have returned the results, enter y, and press enter to automatically download and install. There will be an update prompt later, also enter y and press Enter, and the final message shows that the installation is successful.
Linux builds C++ development and debugging environment
Linux builds C++ development and debugging environment
Execute the g++ --version command to try
Linux builds C++ development and debugging environment
g++ installation successfully.

Compile and run C++ source code

ftp uploads the bubble sort code file create_bubblesort.cc to Linux, the code is as follows

#include<iostream>
#include<string>
using namespace std;

void BubbeSort(int arr[], int n)
{
  int i, j, temp;
  bool exchange;
  for(i = 0; i < n; i++)
  {
    exchange = false;
    for(j = n - 1; j >= i; j--)//前i个是最大的i个
    {
      if(arr[j] < arr[j-1])
      {
        temp = arr[j];
        arr[j] = arr[j-1];
        arr[j-1] = temp;
        exchange = true;
      }
    }
    if(!exchange)
      return;
  }
}

int main()
{
  int arr[10] = {3,8,66,3456,4654,21,88,55,99,66};
  BubbeSort(arr, 10);

  for(int i = 0; i <10; i++)
    cout<<arr[i]<<endl;

  return 0;
}

Executing g++ create_bubblesort.cc will generate the executable file a.out. Execute a.out to input the sorting result.
Linux builds C++ development and debugging environment

gdb debugging

Linux debugging C++ code requires gdb. yum installation.
Linux builds C++ development and debugging environment
gdb debugging process following
Linux builds C++ development and debugging environment
last (gdb) environmental inputs quit, press enter, leave gdb return shell.
Linux builds C++ development and debugging environment

to sum up

After installing g++ gdb, the environment is set up. If the yum source configuration is correct, there will be no major problems.

Guess you like

Origin blog.51cto.com/14947900/2540174