1. 程式人生 > 實用技巧 >centos7 編寫c++ helloworld程式並執行

centos7 編寫c++ helloworld程式並執行

安裝perl支援

yum -ygroupinstallperl*

#安裝gcc

yum -y installgcc

#安裝g++

yum-y installgcc-c++

yum-yinstalllibstdc++-devel

#yum-yinstall cmake3

#安裝其它所需的包

安裝一個老包ncurses,VIM會用到

yum -y install ncurses-devel

或者 sudo apt install libncurses5-dev

安裝m4

wgethttp://mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz

tar-xzvfm4-1.4.13.tar.gz&& cdm4-1.4.13&& ./configure-prefix=/usr/local && make&&makeinstall

安裝autoconf

wgethttp://mirrors.kernel.org/gnu/autoconf/autoconf-2.65.tar.gz

tar-xzvfautoconf-2.65.tar.gz&& cdautoconf-2.65&& ./configure-prefix=/usr/local && make&&makeinstall

安裝automake

wgethttp://mirrors.kernel.org/gnu/automake/automake-1.11.tar.gz

tarxzvfautomake-1.11.tar.gz &&cdautomake-1.11&& ./configure-prefix=/usr/local && make&&makeinstall

安裝libtool

wgethttp://mirrors.kernel.org/gnu/libtool/libtool-2.2.6b.tar.gz

tarxzvflibtool-2.2.6b.tar.gz&& cdlibtool-2.2.6b&& ./configure-prefix=/usr/local && make&&makeinstall

安裝Python2 開發包

yuminstall -ypython-devel

wgethttps://www.python.org/ftp/python/3.6.0/Python-3.6.0a1.tar.xz

tarxvfPython-3.6.0a1.tar.xz&&cdPython-3.6.0a1&&./configure-prefix=/usr/local&&make&&makeinstall

安裝git

sudo yum -y install git
安裝svn

yuminstall-ysubversion

#如果有需要安裝python3,(VIM的YCM需要python支援,需要版本python2.6+ 或者3,選擇一個)

wgethttps://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz

tar-xvJfPython-3.6.2.tar.xz

cdPython-3.6.2

./configureprefix=/usr/local/python3

make&&makeinstall

安裝VIM8.0

安裝python3.6.5:

前戲:yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel make cmake gcc gcc-c++

我是用root直接操作的:

cd /usr/local/src

wgethttps://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz

tar zxvf Python-3.6.5.tgz

cd Python-3.6.5.tgz

./configure --prefix=/usr/local/Python3.6.5 && make && make install

echo "export PATH=$PATH:/usr/local/Python3.6.5/bin" >> /etc/profile

source /etc/profile

python3 -V檢視版本是否安裝成功

更新vim

安裝依賴包:

yum install -y ruby ruby-devel lua lua-devel luajit \
luajit-devel ctags git python-devel \
python36-devel tcl-devel \
perl perl-devel perl-ExtUtils-ParseXS \
perl-ExtUtils-XSpp perl-ExtUtils-CBuilder \
perl-ExtUtils-Embed libX11-devel

刪除舊版本的vim:yum -y remove vim

git下載vim8.0(首先要安裝git就不用說了吧):git clone https://github.com/vim/vim.git

進入vim的目錄進行編譯安裝:

./configure --with-features=huge \
--enable-multibyte \
--enable-rubyinterp=yes \
--enable-python3interp=yes \
--with-python3-config-dir=/usr/local/Python3.6.5/lib/python3.6/config-3.6m-i386-linux-gnu \
--enable-perlinterp=yes \
--enable-luainterp=yes \
--enable-gui=gtk2 \
--enable-cscope \
--prefix=/usr/local/Vim8.0 && make VIMRUNTIMEDIR=/usr/local/Vim8.0/share/vim/vim81 && make install

設定vim的環境:

echo "export PATH=$PATH:/usr/local/Vim8.0/bin" >> /etc/bashrc

source /etc/bashrc

檢視vim版本資訊:

vim --version

安裝成功後:

--------------------------------------------------------------------------------------------

新建一個hello.cpp 檔案

命令列:vim hello.cpp

按insert鍵 開始寫 程式碼

#include<iostream>

using namespace std;

int main(){

cout<<"Hello World" <<endl;

return 0;

}

按: 鍵 進入 vim 的命令列,輸入 wq 儲存退出

用 g++ hello.cpp -o hello 命令進行編譯

用 ./hello 執行,螢幕出現 HelloWorld