Embedded Linux learning 2 - build Ubuntu18.04 in C, C ++ environment

1.C, C ++ environment to build

Open the terminal using sudo su to root mode, and then update the update package list with apt-get.

sudo su

apt-get update

image

Ubuntu's package manager apt c, c ++ environment are integrated in the build-essential, so install build-essential installed on c and c ++ environment a.

apt-get install build-essential

image

When you install the wrong times, run apt or apt-get will have locked file, the two lock files deleted, and then reconfigure the package.

rm /var/lib/dpkg/lock

rm /var/lib/dpkg/lock-frontend

dpkg --configure -a

image

And then re-install build-essential (after experiencing y / y where n are input carriage return), query gcc and g ++ version, you can see gcc and g ++ version is 7.4.0.

gcc --version

g++ --version

image

Then install vim editor (after experiencing y / n where y carriage are input).

apt-get install vim

image

And then query the version of vim, to see if the installation was successful.

vim --version

image

At this point c, c ++ environment to build complete, the following is to use vim and c language, c ++ compiler running method of.

2.vim use

First into the documents folder, create a new folder c_files, into the folder.

cd Documents

mkdir c_files

cd c_files

image

Then use vim create a new c file, and open the file (New File and Open File command, if no such file in the current directory, it will create a new one).

vim hello.c

image

image

Press 'i' key on the keyboard to enter the insert mode, becomes the lower left corner insert, now ready to write the code.

image

Writing the following code:

#include “stdio.h”

int main ()

{

    printf(“Hello world!”);

    return 0;

}

image

After clicking esc on the keyboard to insert the lower left corner of the disappearance, then enter: wq, Enter to exit (in the input mode, press esc to enter the command mode,: wq is to save and exit).

image

3.gcc, g ++ to use

Use gcc compiler quit after just written c file, and then view the file with ls, run the file, appears underneath the words hello world (forget to write line breaks ...).

c gcc compiler command file format: gcc [c filename] -o [executable file name]

gcc hello.c –o hello

./hello

image

Then use vim to write a c ++ file, hello.cpp

#include “iostream”

using namespace std;

int main ()

{

    cout<<”Hello world!”<<endl;

    return 0;

}

image

The same as just compile the cpp file, the compiler uses g ++, execution file name is taken as hello2, execute the file, hello world appears.

image

Guess you like

Origin www.cnblogs.com/mrluka/p/12104261.html