1. 程式人生 > >兩種途徑簡單安裝g++

兩種途徑簡單安裝g++

裝好的Ubuntu系統預設已自帶gcc(C編譯器),但不帶g++。為了能編譯C++程式,我們需要安裝g++。在不使用Synaptic Package Manager的情況下,推薦如下2種方式安裝:


1) 只安裝單獨的g++包。

[email protected]:~/Downloads/cmake-3.1.0$ g++ --version

The program 'g++' can be found in the following packages:

* g++

* pentium-builder

Try: sudo apt-get install <selected package>


按這個提示執行命令則可: (注意:需要聯網哦,因為apt-get...)

[email protected]:~/Downloads/cmake-3.1.0$ sudo apt-get install g++



2) 安裝build-essential包。

它是一個 meta package,包含了很多與編譯有關的軟體包。用命令 apt-cache depends "build-essential" 可以檢視其依賴項:


如果你需要進行軟體的編譯,需要gcc/g++等,都需要用到這個。當然你也可以分別單獨安裝gcc/g++的軟體包,用build-essential 只不過方便管理罷了!


安裝方法:

[email protected]:~/Downloads/cmake-3.1.0$ sudo apt-get install build-essential


出現的錯誤:

[email protected]:~$ sudo apt-get install build-essential

Reading package lists... Done

Building dependency tree

Reading state information... Done

Package build-essential is not available, but is referred to by another package.

This may mean that the package is missing, has been obsoleted, or is only available from another source

E: Package build-essential has no installation candidate


試了:

[email protected]:~/Downloads/cmake-3.1.0$ sudo apt-get update

[email protected]:~/Downloads/cmake-3.1.0$ sudo apt-get install build-essential


依舊不行。Google了一下,說是需要清理package cache,可以這樣解決:

This are a lot and clean of package cache

Open a Terminal from the menu Applications → Accessories → Terminal and type:

sudo dpkg --configure -a

sudo apt-get -f install

sudo apt-get --fix-missing install

sudo apt-get clean

sudo apt-get update

sudo apt-get upgrade

sudo apt-get dist-upgrade

sudo apt-get install build-essential

sudo apt-get clean

sudo apt-get autoremove


我照做了,但是第一步就無法進行:

[email protected]:/$ sudo dpkg --configure -a

Setting up rtl8188eu-dkms (0+git20130406) ...

Loading new rtl8188eu-0+git20130406 DKMS files...

First Installation: checking all kernels...

Building only for 3.13.0-32-generic

Building initial module for 3.13.0-32-generic


Error! Bad return status for module build on kernel: 3.13.0-32-generic (x86_64)

Consult the make.log in the build directory

/var/lib/dkms/rtl8188eu/0+git20130406/build/ for more information.

dpkg: error processing rtl8188eu-dkms (--configure):

subprocess installed post-installation script returned error exit status 10

Errors were encountered while processing:

rtl8188eu-dkms


這個錯誤是涉及到我在這之前安裝過的USB無線網絡卡驅動程式。開啟build/下面的make.log檔案:

DKMS make.log for rtl8188eu-0+git20130406 for kernel 3.13.0-32-generic (x86_64)

Wed Dec 24 19:36:53 CST 2014

make ARCH=x86_64 CROSS_COMPILE= -C /lib/modules/3.13.0-32-generic/build M=/var/lib/dkms/rtl8188eu/0+git20130406/build  modules

make[1]: Entering directory `/usr/src/linux-headers-3.13.0-32-generic'

 CC [M]  /var/lib/dkms/rtl8188eu/0+git20130406/build/core/rtw_cmd.o

In file included from /var/lib/dkms/rtl8188eu/0+git20130406/build/core/rtw_cmd.c:23:0:

/var/lib/dkms/rtl8188eu/0+git20130406/build/include/osdep_service.h: In function ‘thread_enter’:

/var/lib/dkms/rtl8188eu/0+git20130406/build/include/osdep_service.h:1397:2: error: implicit declaration of function ‘daemonize’ [-Werror=implicit-function-declaration]

cc1: some warnings being treated as errors

make[2]: *** [/var/lib/dkms/rtl8188eu/0+git20130406/build/core/rtw_cmd.o] Error 1

make[1]: *** [_module_/var/lib/dkms/rtl8188eu/0+git20130406/build] Error 2

make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-32-generic'

make: *** [modules] Error 2


這些完全就是之前我嘗試安裝網絡卡時不成功的嘗試,留下的後遺症。我大概明白什麼是package cache了,但是到它提示的路徑下面/var/lib/dkms/直接刪除了dkms資料夾,重試“sudo dpkg --configure -a”就會重新自動又生成出來/var/lib/dkms/,怎麼才能清除?看到這篇http://oss.org.cn/html/47/n-67447.html關於Linux下解除安裝軟體的方法,我嘗試了:

[email protected]:/var$ sudo dpkg -r dkms這樣就算解除安裝啦

(Reading database ... 144327 files and directories currently installed.)

Removing dkms ...

Processing triggers for man-db ...

[email protected]:/var$ sudo dpkg -r rtl8188eu-dkms

(Reading database ... 144303 files and directories currently installed.)

Removing rtl8188eu-dkms ...

/var/lib/dpkg/info/rtl8188eu-dkms.prerm: 9: /var/lib/dpkg/info/rtl8188eu-dkms.prerm: dkms: not found


解除安裝後。重試:

[email protected]:~/Downloads/cmake-3.1.0$ sudo apt-get update

….

Hit http://cn.archive.ubuntu.com precise-backports/universe Translation-en

Fetched 5,851 kB in 17s (344 kB/s)

W: Failed to fetch bzip2:/var/lib/apt/lists/partial/security.ubuntu.com_ubuntu_dists_precise-security_main_source_Sources  Hash Sum mismatch

W: Failed to fetch bzip2:/var/lib/apt/lists/partial/security.ubuntu.com_ubuntu_dists_precise-security_main_i18n_Translation-en  Hash Sum mismatch

E: Some index files failed to download. They have been ignored, or old ones used instead.


沒關係,繼續:


[email protected]:~/Downloads/cmake-3.1.0$ sudo apt-get install build-essential

Reading package lists... Done

Building dependency tree  

Reading state information... Done

The following extra packages will be installed:

 dpkg-dev fakeroot g++ g++-4.6 libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libdpkg-perl libstdc++6-4.6-dev libtimedate-perl

Suggested packages:

 debian-keyring g++-multilib g++-4.6-multilib gcc-4.6-doc libstdc++6-4.6-dbg libstdc++6-4.6-doc

The following NEW packages will be installed:

 build-essential dpkg-dev fakeroot g++ g++-4.6 libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libdpkg-perl libstdc++6-4.6-dev libtimedate-perl

0 upgraded, 11 newly installed, 0 to remove and 147 not upgraded.

Need to get 9,475 kB of archives.

After this operation, 28.8 MB of additional disk space will be used.

Do you want to continue [Y/n]? y

Get:1 http://cn.archive.ubuntu.com/ubuntu/ precise/main libstdc++6-4.6-dev amd64 4.6.3-1ubuntu5 [1,660 kB]

Get:2 http://cn.archive.ubuntu.com/ubuntu/ precise/main g++-4.6 amd64 4.6.3-1ubuntu5 [6,954 kB]

Get:3 http://cn.archive.ubuntu.com/ubuntu/ precise/main g++ amd64 4:4.6.3-1ubuntu5 [1,442 B]

Get:4 http://cn.archive.ubuntu.com/ubuntu/ precise/main libtimedate-perl all 1.2000-1 [41.6 kB]

Get:5 http://cn.archive.ubuntu.com/ubuntu/ precise-updates/main libdpkg-perl all 1.16.1.2ubuntu7.5 [182 kB]

Get:6 http://cn.archive.ubuntu.com/ubuntu/ precise-updates/main dpkg-dev all 1.16.1.2ubuntu7.5 [468 kB]

Get:7 http://cn.archive.ubuntu.com/ubuntu/ precise-updates/main build-essential amd64 11.5ubuntu2.1 [5,816 B]

Get:8 http://cn.archive.ubuntu.com/ubuntu/ precise/main fakeroot amd64 1.18.2-1 [87.2 kB]

Get:9 http://cn.archive.ubuntu.com/ubuntu/ precise/main libalgorithm-diff-perl all 1.19.02-2 [50.7 kB]

Get:10 http://cn.archive.ubuntu.com/ubuntu/ precise/main libalgorithm-diff-xs-perl amd64 0.04-2build2 [12.4 kB]

Get:11 http://cn.archive.ubuntu.com/ubuntu/ precise/main libalgorithm-merge-perl all 0.08-2 [12.7 kB]

Fetched 9,475 kB in 5s (1,700 kB/s)            

Selecting previously unselected package libstdc++6-4.6-dev.

(Reading database ... 144049 files and directories currently installed.)

Unpacking libstdc++6-4.6-dev (from .../libstdc++6-4.6-dev_4.6.3-1ubuntu5_amd64.deb) ...

Selecting previously unselected package g++-4.6.

Unpacking g++-4.6 (from .../g++-4.6_4.6.3-1ubuntu5_amd64.deb) ...

Selecting previously unselected package g++.

Unpacking g++ (from .../g++_4%3a4.6.3-1ubuntu5_amd64.deb) ...

Selecting previously unselected package libtimedate-perl.

Unpacking libtimedate-perl (from .../libtimedate-perl_1.2000-1_all.deb) ...

Selecting previously unselected package libdpkg-perl.

Unpacking libdpkg-perl (from .../libdpkg-perl_1.16.1.2ubuntu7.5_all.deb) ...

Selecting previously unselected package dpkg-dev.

Unpacking dpkg-dev (from .../dpkg-dev_1.16.1.2ubuntu7.5_all.deb) ...

Selecting previously unselected package build-essential.

Unpacking build-essential (from .../build-essential_11.5ubuntu2.1_amd64.deb) ...

Selecting previously unselected package fakeroot.

Unpacking fakeroot (from .../fakeroot_1.18.2-1_amd64.deb) ...

Selecting previously unselected package libalgorithm-diff-perl.

Unpacking libalgorithm-diff-perl (from .../libalgorithm-diff-perl_1.19.02-2_all.deb) ...

Selecting previously unselected package libalgorithm-diff-xs-perl.

Unpacking libalgorithm-diff-xs-perl (from .../libalgorithm-diff-xs-perl_0.04-2build2_amd64.deb) ...

Selecting previously unselected package libalgorithm-merge-perl.

Unpacking libalgorithm-merge-perl (from .../libalgorithm-merge-perl_0.08-2_all.deb) ...

Processing triggers for man-db ...

Setting up libtimedate-perl (1.2000-1) ...

Setting up libdpkg-perl (1.16.1.2ubuntu7.5) ...

Setting up dpkg-dev (1.16.1.2ubuntu7.5) ...

Setting up fakeroot (1.18.2-1) ...

update-alternatives: using /usr/bin/fakeroot-sysv to provide /usr/bin/fakeroot (fakeroot) in auto mode.

Setting up libalgorithm-diff-perl (1.19.02-2) ...

Setting up libalgorithm-diff-xs-perl (0.04-2build2) ...

Setting up libalgorithm-merge-perl (0.08-2) ...

Setting up libstdc++6-4.6-dev (4.6.3-1ubuntu5) ...

Setting up g++-4.6 (4.6.3-1ubuntu5) ...

Setting up g++ (4:4.6.3-1ubuntu5) ...

update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode.

Setting up build-essential (11.5ubuntu2.1) ...

[email protected]:/var$


安裝順利完成。


如果你沒有網路,可以到這裡http://packages.ubuntu.com/zh-cn/precise/build-essential,去下載安裝包。