2015年10月4日 星期日

Virtualbox kernel service is not running

最近更新了 VirtualBox 4.3.30 版本後,然後再 Client OS Ubuntu 12.04 LTS 中重新安裝 Guest Additions 後;重新啟動 Ubuntu 時卻發現登入的時候會出現 "Virtualbox kernel service is not running" 的訊息,如下畫面所示:



最後在 "VirtualBox Ubuntu 14.04 - vboxclient the virtualbox kernel service is not running" 找到了解法,透過下面的方式重新安裝 Guest Additions 也無法解決問題。
linux:/media/VBOXADDITIONS_4.3.30_101610$ sudo ./VBoxLinuxAdditions.run

直到執行下面的命令後:
linux:~$ sudo /etc/init.d/vboxadd setup

出現下面的錯誤訊息:


之後檢查訊息所提供的提示去檢查 /var/log/vboxadd-install.log 檔案,其訊息如下圖所示:



由上圖所示可以發現無法編譯成功,所以回想之前我有將 gcc 升級到 gcc5,且將其設定為預設的編譯器版本,因此將 gcc 版本設定回原本的 4.6.4 版本後,重新執行 vboxadd setup 就可以順利編譯成功,重新開機後也沒出現 "Virtualbox kernel service is not running" 的警告訊息囉。

2015年9月23日 星期三

查詢所安裝的 Ubuntu 版本訊息

1.lsb_release -a 查詢版本資訊
linux:~/Downloads$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.4 LTS
Release: 12.04
Codename: precise

2.cat /etc/*release
linux:~/Downloads$ cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.4 LTS"
NAME="Ubuntu"
VERSION="12.04.4 LTS, Precise Pangolin"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu precise (12.04.4 LTS)"
VERSION_ID="12.04"

3. cat /etc/issue 或 cat /etc/issue.net
linux:~/Downloads$ cat /etc/issue
Ubuntu 12.04.4 LTS \n \l

linux:~/Downloads$ cat /etc/issue.net
Ubuntu 12.04.4 LTS

4. cat /proc/version 可以得知核心版本、何時編譯且用哪一版的 gcc 所編譯
linux:~/Downloads$ cat /proc/version
Linux version 3.8.0-42-generic (buildd@allspice) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #62~precise1-Ubuntu SMP Wed Jun 4 22:04:18 UTC 2014

5. uname -r 得知核心版本資訊
linux:~/Downloads$ uname -r
3.8.0-42-generic


6. uname -i 或 uname -m 取得目前的架構是 64 或 32 位元
linux:~/Downloads$ uname -i
x86_64
linux:~/Downloads$ uname -m
x86_64

7.file /sbin/init 取得目前的架構是 64 或 32 位元
linux:~/Downloads$ file /sbin/init
/sbin/init: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x7aa29ded613e503fb09fb75d94026f3256f01e7a, stripped

8. dpkg --print-architecture 取得目前的架構是 64 或 32 位元
linux:~/Downloads$ dpkg --print-architecture
amd64

9. getconf LONG_BIT 取得目前的架構是 64 或 32 位元
linux:~/Downloads$ getconf LONG_BIT
64

10. uname -a 得知核心版本資訊以及架構 i386 為 32 位元; x86_64 為 64 位元
linux:~/Downloads$ uname -a
Linux linux 3.8.0-42-generic #62~precise1-Ubuntu SMP Wed Jun 4 22:04:18 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

11. cat /proc/cpuinfo 取的 CPU 資訊
linux:~/Downloads$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model  : 42
model name : Intel(R) Pentium(R) CPU G840 @ 2.80GHz
stepping : 7
cpu MHz  : 2792.759
cache size : 6144 KB
fpu  : yes
fpu_exception : yes
cpuid level : 5
wp  : yes
flags  : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm constant_tsc rep_good nopl pni monitor ssse3 lahf_lm
bogomips : 5585.51
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:




[參考資料]

如何升級升級/降級 Ubuntu 12.04 的 Firefox 以及安裝 Chrome

你可以透過 apt-cache show firefox | grep Version 指令來查詢目前 Ubuntu 所提供的套件版本資訊。在執行前請先執行 sudo apt-get update 指令以確保得到是最新資訊。執行後應該會顯示如下的訊息:
linux$ apt-cache show firefox | grep Version
Version: 41.0+build3-0ubuntu0.12.04.1
Version: 11.0+build1-0ubuntu4

更新 firefox 只需要下達如下指令即可,如果有新的版本可用便會開始安裝新版本。
sudo apt-get update
sudo apt-get install firefox

更新完後新版本如果有問題,如何將 firefox 安裝成以前的版本呢?

1. 到 https://launchpad.net/ubuntu/precise/+source/firefox 下載你要的版本。
這邊我們下載 firefox version 31.0 64 bit https://launchpad.net/~ubuntu-mozilla-security/+archive/ubuntu/ppa/+build/6185582/+files/firefox_31.0%2Bbuild1-0ubuntu0.12.04.1_amd64.deb

2. 解除安裝 firefox
sudo apt-get purge firefox


3. 安裝在第一步驟所下載的 firefox 套件。
sudo dpkg -i firefox_31.0+build1-0ubuntu0.12.04.1_amd64.deb

萬一在你下在 firefox 舊套件前你就把你的 firefox 移除的話,你可以透過 wget 來下載套件,然後在執行安裝即可。
wget https://launchpad.net/~ubuntu-mozilla-security/+archive/ubuntu/ppa/+build/6185582/+files/firefox_31.0%2Bbuild1-0ubuntu0.12.04.1_amd64.deb

如何安裝 Chrome,到 https://www.google.com.tw/chrome/browser/desktop/ 網頁按"下載"按鈕後;選擇你的 Linux 平台後按 "接受並安裝" 按鈕後;點選 "Open with" 然後選擇 "Ubuntu Software center" 如下圖所示:

等Ubuntu Software center開啟後按 install 按鈕即可以安裝 Chrome;如下圖所示:

[參考鏈結]

2015年9月21日 星期一

如何更新 Ubuntu 12.04 上的 gcc 與 g++

當安裝好 Ubuntu 12.04 其預設安裝的 gcc 與 g++ 版本為 4.6 你可以透過 g++ --version 來查詢你系統上的版本:
linux:~$ g++ --version
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

更新步驟可依序執行下列指令即可:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-5 g++-5

為了讓 update-alternatives 知道我們系統上有 2 套 gcc 與 g++ 編譯器,我們必須為每套 gcc 與 g++ 建立安裝紀錄;然後再透過 config 來設定系統所要載入的版本,設定方法如下:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 40 --slave /usr/bin/g++ g++ /usr/bin/g++-5
sudo update-alternatives --config gcc

當你執行 sudo update-alternatives --config gcc 會看到如下的選單畫面,而在此畫面我選擇了 2:
linux:~$ sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path              Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gcc-4.6   60        auto mode
  1            /usr/bin/gcc-4.6   60        manual mode
  2            /usr/bin/gcc-5     40        manual mode

Press enter to keep the current choice[*], or type selection number: 2       
update-alternatives: using /usr/bin/gcc-5 to provide /usr/bin/gcc (gcc) in manual mode.

完成上面設定後執行 g++ --version 你應該可以看到如下面的訊息:
linux:~$ g++ --version
g++ (Ubuntu 5.1.0-0ubuntu11~12.04.2) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


[參考連結]

2015年8月25日 星期二

如何透過 adb command 取得Android CPU 資訊

        將手機連上電腦後在 console Mode 下執行 "adb shell cat /proc/cpuinfo" 即可得到如下訊息,如果手機是四核心則會出現四次一樣的訊息。

~$ adb shell cat /proc/cpuinfo

processor : 0
vendor_id : GenuineIntel
cpu family : 6
model  : 90
model name : Intel(R) Atom(TM) CPU  Z3560  @ 1.00GHz
stepping : 0
microcode : 0x34
cpu MHz  : 500.000
cache size : 1024 KB
physical id : 0
siblings : 4
core id  : 0
cpu cores : 4
apicid  : 0
initial apicid : 0
fpu  : yes
fpu_exception : yes
cpuid level : 11
wp  : yes
flags  : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes rdrand lahf_lm 3dnowprefetch ida arat epb dtherm tpr_shadow vnmi flexpriority ept vpid tsc_adjust smep erms

[參考鏈結]

2015年5月26日 星期二

[Error] Invalid conversion from 'int' to 'main(int, char**)::fruit_tea' [-fpermissive]


當你嘗試編譯將 int 數值指定給 enum 型態的變數時,會出現編譯錯誤訊息如下:
Invalid conversion from 'int' to 'main(int, char**)::fruit_tea' [-fpermissive]

範例程式如下:
#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) 
{
 enum fruit_tea { apple, banana, orange } taste;
 taste = 10;
 std::cout << taste << std::endl;
 return 0;
}

解決方法就是將 fpermissive flag 加入到編譯的選項中,下面的圖示是使用 OrWell Dev-C++ IDE,設定方法步驟:點選 project 右鍵 >> Project Options... >> Parameters 在 C++ compiler中填入 -fpermissive 即可。重新編譯程式時,原本錯誤的地方就變成是 Warning 了。


下面有關 fpermissive flag 的解釋擷取至 3.5 Options Controlling C++ Dialect 。主要是讓原本編譯器將某些不合適的 code 判斷為錯誤的訊息改成為警告訊息,以便讓程式可以編譯成功。

-fpermissive
Downgrade some diagnostics about nonconformant code from errors to warnings. Thus, using -fpermissive will allow some nonconforming code to compile. 

上面的例子,想要將整數值指定給列舉型態變數;因為指定的整數值未必在列舉型態的範圍內,所以C++ 禁止將 整數值指定給 列舉型態變數,但可以將列舉型態變數值指定給整數型態變數,因為列舉型態也是一種整數型態。

基本上不建議使用 fpermissive flag 來解此類的問題,如上面所說 整數值未必在 列舉型態的範圍中,允許指定整數值給列舉型態可能會造成不必要的麻煩。


[相關鏈結]

2015年5月21日 星期四

Error C4335: Mac file format detected: please convert the source file to either DOS or UNIX format

最近把一個 Third Party Lib include 到專案內;使用VS 2010 編譯時卻出現下列問題,在 Ubuntu下編譯卻不會這樣的問題發生。比較快的方式是將所有的 Third Party 的 Source code 修正成 Windows 或者 UNIX 的檔案格式。但這樣不是很理想,我們不應該修改 Third Party 的Source code 除非必要。這樣以後要 Upgrade 才不會遇到太多問題。
 
error C4335: Mac file format detected: please convert the source file to either DOS or UNIX format

要解決這個問題又不改到 Third Party Source Code 的方法就是直接把那個 C4335 關閉即可,下面是如何關閉的圖示:


  • 點選專案 > 右鍵 > 選擇 Properties
  • Configuration Properties > C/C++ > Advanced > Disable Specific Warnings 填入 4335 即可。