2026年9月15日 星期二

Boot to TTY or Graphic Mode in Ubuntu

1. 預設開機直接進入純文字模式 (CLI/TTY)

    sudo systemctl set-default multi-user.target

    sudo reboot

2. 預設開機直接進入圖形模式

    sudo systemctl set-default graphical.target

    sudo reboot

3. 檢查目前預設的啟動模式

    systemctl get-default

4. 不重啟電腦,立即從文字模式進入圖形介面

    sudo systemctl start gdm3

    (註:依據 Ubuntu 版本不同,顯示管理器也可能是 lightdm 或 sddm)

2026年9月14日 星期一

Ubuntu Login keyring password "no longer matches"

 

1.  Update via Seahorse

    a. run seahorse in a terminal.

    b. Look at the sidebar under Passwords and find the item named login.

    c. Right-click on login and select Change Password.

    d. Enter your old system password (the previous password before you changed it) when prompted for the current password.

    e. Enter your new current Ubuntu login password for the new password fields, then save.

 

2. Reset the Keyring (If old password is unknown) 

    a. Delete the login keyring file: ~/.local/share/keyrings/login.keyring 

    b. Log out

 

 

Shell(.sh)


1. 在終端機螢幕上顯示文字、變數內容,或將訊息輸出到檔案中

    echo "Hello World"

2. 定義變數

    <variable name>=<data>

規則:

    a. 等號前後,不能有空格

    b. 變數名稱只能是英文和數字,且數字不能在開頭 

    c. 變數內容,如需空白,可放在雙引號 "" 或是單引號 '' 裡面

        -雙引號中若有特殊字元,例如 $,會保有原本的特性。

        -單引號中所有的字元即為一般字元,沒有任何功能 。

    d. 反斜線 \, 可以跳脫其後接的第一個字元本身的功能  

3.  取得變數內容

    $<variable name>
    ${<variable name>}

4. 指令內容,可以使用 $(command) 或是 `command` 取得其他指令的值。

    username=$(whoami)
    echo $username
    user 

5. 取消變數設定

    unset username

6. 取得所有環境變數

    env

7.  自訂變數轉成環境變數

    export <variable name> 

8.  查看目前開放哪些環境變數

    export

9.  列出所有的變數:自訂變數,環境變數,bash 本身變數

    set

10. 語系相關

    a. 查看目前語系變數:locale

    b. 查看支援哪些語系:locale -a 

    c. 暫時修改語系的變數:export LANG=zh_TW.utf8

        只要有設定 LANG 或是 LC_ALL,則其他的變數就會被這兩個變數自動取代。

    d. 永久修改語系的變數:打開 /etc/locale.conf, 加入或更改:LANG="en_US.utf-8"

11.  讀取鍵盤輸入,當作變數值

    read <option> <variable name>

    option :
        -a : array,變數為陣列格式,以空白隔開,依序存入陣列中,索引從0開始。
        -p : prompt,跳出提示字串。
        -t : timeout,設定秒數內沒有完成則結束。 

12. 宣告變數的類型,沒指定,預設為字串。只有整數才可運算。 

    declare <option> <variable name>

    option :
        -a : 變數為陣列格式,以空白隔開,依序存入陣列中,索引從0開始。
        -i : 整數類型,可以進行數值運算,但是預設只能做到整數型態。
        -l : 將變數內容轉換為小寫。
        -r : 變數僅為 readonly,不可被更改也不可以被 unset。
        -u : 將變數內容轉換為大寫。
        -x : 開放變數轉換成環境變數,等同使用 export。

 

13. 比較符號:

    字串比較符號:
        =:等於(字串相等)
        !=:不等於(字串不相等)
        <:小於(按字典序比較)
        >:大於(按字典序比較)
        -z:檢查字串是否為空(長度為零)
        -n:檢查字串是否非空(長度大於零)

    數字比較符
號:
        -eq:等於(數字相等)
        -ne:不等於(數字不相等)
        -lt:小於(數字小於)
        -le:小於或等於(數字小於或等於)
        -gt:大於(數字大於)
        -ge:大於或等於(數字大於或等於)

14. 檔案測試符號: 

    -e FILE:如果 FILE 存在,則為真。
    -f FILE:如果 FILE 存在且為一個檔案,則為真。
    -d FILE:如果 FILE 存在且為一個目錄,則為真。
    -s FILE:如果 FILE 存在且檔案大小不為零,則為真。
    -r FILE:如果 FILE 存在且可讀取(有讀取權限),則為真。
    -w FILE:如果 FILE 存在且可寫入(有寫入權限),則為真。
    -x FILE:如果 FILE 存在且可執行(有執行權限),則為真。
    -L FILE:如果 FILE 存在且為一個符號連結(軟連結),則為真。
    -p FILE:如果 FILE 存在且為一個命名管道(FIFO),則為真。
    -c FILE:如果 FILE 存在且為一個字元特殊文件,則為真。 

15. 流程控制:

    a. if, then else fi 

        if 條件
        then
            # 如果條件為True,執行這裡的命令
        else
            # 如果條件為False,執行這裡的命令
        fi

    b. if … elif … fi

        if 條件1
        then
            # 如果條件1為真,執行這裡的命令
        elif 條件2
        then
            # 如果條件2為真,執行這裡的命令
        else
            # 如果以上所有條件都不滿足,執行這裡的命令
        fi

    c.  case

        case 值 in
            條件1)
                    條件1匹配時執行的命令

                    ;;
            條件2)
                    條件2匹配時執行的命令

                    ;; 
            *)

                    沒有任何匹配時執行的命令

                    ;;
        esac

    d. for

        for 變數 in 列表; do
            執行的命令
        done

    e. while

        while 條件
            do
                # 當條件為真時執行的程式碼
        done

16. 函式(Function)結構: 

    function 函式名稱 {
        # 函式的程式碼
        # 可以使用傳遞給函式的參數
        # 函式的操作
        # ...
        # 返回值(可選)
    }

 

17. 結果輸出導向: 

    a. >(複寫導向)

        echo "Hello" > output.txt

    b. >>(附加導向):將指令的標準輸出以附加(Append)的方式存入檔案。它不會刪除舊資料,而是將新資料寫在檔案的最末端。

        echo "Hello" >> output.txt

    c. &>(全輸出導向):標準輸出(stdout)和標準錯誤輸出(stderr)「同時」存入同一個檔案中。無論指令執行成功還是發生錯誤,所有的訊息都會被寫進檔案(並採覆寫模式)。&> 與較傳統的寫法 > 檔案名稱 2>&1 效果完全相同。)

        echo "Hello" &> output.txt

    d. 2>&1 :將標準錯誤輸出(stderr,代號 2)重新導向至標準輸出(stdout,代號 1)

        在 Linux 與 Bash 中,每個執行中的程式都有預設的資料流代號: 

            0:標準輸入(stdin,鍵盤輸入)

            1:標準輸出(stdout,正常顯示的訊息)

            2:標準錯誤(stderr,錯誤或警告訊息) 

 

18. 管線命令 (pipe):管線命令使用『 | 』,上一個指令輸出,給下一個指令使用。
    例:ls -al /etc | less
    ls 指令輸出後的內容,給 less 讀取

  

  

19. Shell Script基本結構元素:

    1. Shebang行:通常以#! 開頭後面接著一個解釋器(interpreter)的路徑,用來告訴系統使用哪種shell來執行script,系統會自動使用指定的解釋器執行script。

        #!/bin/bash

    2. 註釋:使用 # 符號來添加註釋。註釋不會被執行僅供備註閱讀。

        # 這是一個註釋

    3. 變數:

        variable="Hello World!"

    4. 特殊變數:

        $0, ${BASH_SOURCE[0]}:這個變數代表目前shellscript程式的檔案名稱(包括路徑)。

         $1, $2, ... $n:用於獲取命令行參數傳遞給程式的值。$1代表第一個參數,$2代表第二個參數,依此類推,$n代表第n個參數。

    5.  特殊的環境變數

        $HOME:代表當前的主目錄路徑,通常用於訪問家目錄。
        $USER:代表當前使用者名。
        $PWD:代表當前工作目錄的路徑。
        $SHELL:代表當前所使用的Shell的路徑。
        $PATH:包含了Shell用於查詢可執行命令的目錄列表。

    6. 指令:

        echo "This is a shell script."

    7. 流程控制:(如 if、else、case)和迴圈(如 for、while)來執行流程控制
        if [ $age -ge 18 ]; then
            echo "You are an adult."
        else
            echo "You are not yet an adult."
        fi

    8. 函數:函數能夠接受參數與返回值。

        function afunc {
            echo "Hello, $1!"
        }
        afunc "Alice"

 

 參考網站:

    Shell 的變數設定 

    Shell Script 基礎介紹 

 

 

2026年8月25日 星期二

Format USB flash drive in Ubuntu

 1. 查詢磁碟位置與資訊(判斷正確位置)

    指令: lsblk

2. Un-mount磁碟,避免運作中

    sudo umount /dev/sda1(sda1為一個例子,要看實際位置,參考lsblk)

3. 格式化磁碟

    exFAT格式:sudo mkfs.exfat /dev/sda1(跨 Windows/Mac/Linux,支援大於 4GB 檔案)

                          sudo exfatlabel /dev/sda1 "NewDiskName"(修改磁碟名稱)

    FAT32格式:sudo mkfs.vfat /dev/sda1 (相容性最高,但單一檔案不能大於 4GB)

                          sudo mlabel -i /dev/sda1 ::"NewDiskName"(修改磁碟名稱)

    NTFS格式:sudo mkfs.ntfs /dev/sda1  (Windows 系統常用)

                          sudo ntfslabel /dev/sda1 "NewDiskName"(修改磁碟名稱)

    ext4格式   :sudo mkfs.ext4 /dev/sda1 (Linux 專用格式)

                          sudo e2label /dev/sdda1 "NewDiskName"(修改磁碟名稱)

    P.S. 如果找不到,安裝格式化程式:sudo apt install exfatprogs


磁碟相關指令:

lsblk(List Block Devices)

blkid(Block Identification)

mount

umount

fdisk -l(Fixed Disk or Format Disk)

df -h(Disk Free)


2026年8月24日 星期一

Visual Studio Code(C/C++ Auto Format)

C/C++ Auto Format

1. File --> Preferences-->Settings

2. Extensions-->C/C++-->Formatting

3. C_Cpp: Clang_format_fallback Style

4. Sample: {BasedOnStyle: LLVM, BreakBeforeBraces: Linux, SpaceBeforeParens: Never, AllowShortIfStatementsOnASingleLine: true, MaxEmptyLinesToKeep: 8, ColumnLimit: 0, UseTab: Always, IndentWidth: 4, TabWidth: 4}


Tab(Keep tab, Don't change to space key)

1. File --> Preferences-->Settings

2. Search: "Insert Spaces"

3. UnCheck:

        Editor: Insert Spaces

        Editor Detect Indentation

2026年8月11日 星期二

xrandr (Linux 多螢幕控制)

 

xrandr指令:

    X Resize and Rotate 的縮寫,X:代表 X 視窗系統(X Window System)。

    官方原始碼由 X.Org 專案維護。X.Org 官方網站、X.Org XRandR 說明頁面

    執行 xrandr --help查詢說明,主要使用--output後面相對參數。    

    指令介紹(包含:xrandr, cvt(Coordinated Video timing)):

        https://wiki.archlinuxcn.org/zh-tw/Xrandr

    圖形版:

        https://wiki.archlinuxcn.org/zh-tw/Xrandr


    多螢幕設定:

        左右延伸螢幕:將 DP-1 放的右側

            xrandr --output DP-0 --auto --output DP-1 --auto --right-of DP-0

        上下延伸螢幕:將DP-1放下方

            xrandr --output DP-0 --auto --output DP-1 --auto --below DP-0

        設定主螢幕(包含釘選工作列的位置)

            xrandr --output DP-0 --primary

        複製螢幕(鏡像同步):讓兩個螢幕顯示相同畫面

            xrandr --output DP-0 --auto --output DP-1 --auto --same-as DP-0

        關閉特定螢幕:關閉 DP-0 輸出:

            xrandr --output DP-0 --off


Ref:

    https://yowlab.idv.tw/wordpress/?p=1337


2026年7月30日 星期四

Install Qt6 in Ubuntu 22.04

Install:

1. sudo apt install qtcreator

2. sudo apt install qtcreator-data qtcreator-doc

3. sudo apt install qt6-base-dev

4. which qmake6 (Get qmake6 location)


Env settings:

Qt Creator: Tools->Options->Kits->Kits

    Manul->Desktop(Default)->Qt version: Qt 6.2.4(System)

Qt Creator: Tools->Options->Kits->Qt Versions

    qmake path: /usr/bin/qmake6


2026年7月28日 星期二

Library 降版(Dangerous)

The behavior is dangerous.


 始因:Ubuntu 22.04,安裝gtkmm 3.0出現,lib版本不相容問題。


例:

sudo apt install libgtkmm-3.0-dev

The following packages have unmet dependencies:

 libpango1.0-dev : Depends: gir1.2-pango-1.0 (= 1.50.6+ds-2) but 1.50.6+ds-2ubuntu1 is to be installed

                   Depends: libpango-1.0-0 (= 1.50.6+ds-2) but 1.50.6+ds-2ubuntu1 is to be installed

                   .....


需要從1.50.6+ds-2ubuntu1,降版1.50.6+ds-2


1. 更新apt資料庫

    sudo apt update

2. 檢查是否有此library

    apt-cache policy gir1.2-pango-1.0

3. 降版本(可能有多個library需要降版)

    sudo apt install gir1.2-pango-1.0=1.50.6+ds-2 --allow-downgrades

    sudo apt install libpango-1.0-0=1.50.6+ds-2 --allow-downgrades


4. 降版完成,安裝gtkmm

    sudo apt install libgtkmm-3.0-dev


2026年7月26日 星期日

Library:static、shared與dynamically loaded in Linux

 

Static libraries :

    Static 程式庫用於靜態連結,把一堆 object 檔,用 ar (archiver) 包裝集合起來,檔名以 `.a' 結尾。

    優點:執行效能快,且因靜態連結,不易發生執行時找不到 library 或版本問題。

    缺點:檔案較大,維護度較低


Shared libraries :

    Shared library 程式執行起始時載入,而不是執行中用到才載入。連結階段需要有該程式庫才能進行連結。

    優點:維護彈性較好。

    soname:library 的名稱,例: libmylib.so.1 

    real name:實際放有library程式的檔案名稱,例:libmylib.so.1.0.0

    linker name:連結時的名稱,通常是不含版號,例: libmylib.so


    使用範例:

        * Complie :

            # gcc -c -fPIC LibData1.c LibData2.c

                -fPIC 產生 position-independent code。也可以用 -fpic 參數。

            # gcc -shared -Wl,-soname,libmylib.so.1 LibData1.o LibData2.o -o libmylib.so.1.0.0

                -shared 表示要編譯成 shared library

                -Wl 用於參遞參數給linker,-soname與libmylib.so.1會被傳給linker處理。-soname 用來指名 soname 為 limylib.so.1

                library 會被輸出成 libmylib.so.1.0.0(real name), 若不指定 soname 的話,在編譯結連後的執行檔會以連時的library檔名為 soname,並載入他。否則是載入 soname 指定的 library 檔案。


        * 用 ln 來建立 soname 與 linker name 兩個檔案 :

            # ln -s libmylib.so.1.0.0 libmylib.so.1 <- 連結soname

            # ln -s libmylib.so.1.0.0 libmylib.so    <- 連結函式庫名稱


        * 使用方法 : 與 static library 同 :

            gcc main.c libmylib.so.1.0.0

            or

            gcc main.c -L. -lmylib    #-lmylib ->libmylib.so,透過上面ln取得libmylib.so.1.0.0


            如果目錄下同時有 static 與 shared library 的話,會以 shared 為主,可以使用 -static 參數可以避免使用shared連結。


版本號:

第1碼:原介面有移除或改變,與舊版不相容時。

第2碼:有新增加介面,但相舊介面沒改變,所以與舊版本相容。

第3碼:用於程式內容的修正,介面完全沒有改變。


Dynamically loaded libraries :

    像 windows 所用的 DLL ,在使用到時才載入,編譯連結時不需要相關的 library。動態載入庫常被用於像 plug-ins 的應用.

    動態載入是透過一套 dl function來處理,預設 API如下 :

        #include <dlfcn.h>

        void *handle = dlopen(const char *filename, int flag); // 根據檔名開啟library並回傳handle

        void (*func)(void);                                                         // 宣告function

        func = dlsym(void *handle, const char *symbol);         // 根據symbol,取得function記憶體位置

        int dlclose(void *handle);                                               // 關閉library  

        char *dlerror(void);                                                         // 傳回最近所發生的錯誤訊息。


    使用方法:與Shared Library同,只差別在使用程式碼,如上。


Ref:

[Linux 教學] 用gcc 自製 Library

Program Library HOWTO

Linux 的動態連結與載入 (Dynamic Linking)


Supermium(Chromium支援Window 7, XP)

 Chrome 已停止支援Windows 7,或更舊系統。


Supermium 是由 Shane Fournier 開發的自由及開放原始碼網頁瀏覽器( Chromium 的一個分支)。

介紹(From Wiki):特點是支援已不再受 Chromium 支援的舊版 Microsoft Windows,包括所有 Windows 10 之前的版本,最早可支援 Windows XP。

路徑:https://github.com/win32ss/supermium


Thorium Browser 是一個基於 Chromium 的高效能開源網頁瀏覽器,其特色為極致效能與編譯優化。

路徑:https://thorium.rocks/win7


Ref: https://www.mobile01.com/topicdetail.php?f=300&t=6720648


2026年7月22日 星期三

Linux Man(Manual) Page - (線上手冊)

 章節分類(Sections):

1. 可執行的程式或是 shell 指令

2. 系統呼叫(system calls,Linux 核心所提供的函數)

3. 一般函式庫函數

4. 特殊檔案(通常位於 /dev)

5. 檔案格式與協定,如 /etc/passwd

6. 遊戲

7. 雜項(巨集等,如 man(7)、groff(7))

8. 系統管理者指令(通常是管理者 root 專用的)

9. Kernel routines(非標準)


線上查詢:

    https://man7.org/linux/man-pages/index.html

Program部份:

    gcc : https://man7.org/linux/man-pages/man1/gcc.1.html

    g++: https://man7.org/linux/man-pages/man1/g++.1.html


參考網址:

    第六章、Linux 檔案與目錄管理 - 鳥哥 - 基礎學習篇 - CentOS 7.x

    善用 man 指令查詢 Linux 線上手冊(Man Page)


Visual Studio Code(VS Code) tutorial


1. install VS code

    Download the corresponding version

    https://code.visualstudio.com/download?_exp_download=fb315fc982

    sudo apt install ./<file>.deb

Ref:

    https://code.visualstudio.com/docs/setup/linux

    https://code.visualstudio.com/docs/setup/windows


2. install extension for C/C++ or other

    Start app

    Enter extensions and install: C/C++, C/C++ Extension Pack, C/C++ DevTools, Bookmarks by Alessandro

Ref:

    https://code.visualstudio.com/docs/languages/cpp


3. first program(Hello World) and do debug

    Please check the under link.

    .vscode -- some setting file

        tasks.json (compiler build settings)

        launch.json (debugger settings)

        c_cpp_properties.json (compiler path and IntelliSense settings)

    Debug: 

        a. Open main.cpp in VS code.

        b. Add a breakpoint in source code

        c. Press the play button(in the right-up location),  select Debug C/C++ File in the drop-down

Ref:

    https://code.visualstudio.com/docs/cpp/config-linux


4. Debugging with Multiple Files

    Previous step will generate tasks.json. Modify task.json.

    Replease

    "${file}",

    to

    "file1.cpp",

    "file2.cpp",

Ref:

    http://antares.cs.kent.edu/~csi/blog/vscodemultiple.html



2026年7月21日 星期二

Install ImageMagick 7 in Ubuntu 22.04

Use source code

1.  Download the newest source code from official website: Source code(zip) or Source code(tar.gz)

https://github.com/ImageMagick/ImageMagick/releases

2. Decompress source codes and enter the folder

cd ImageMagick-7.1.2-27

3. Set build environment

./configure

4. build code

make

5. install ImageMagick

sudo make install

6. update dynamic shared library

sudo ldconfig /usr/local/lib



Ref:

https://imagemagick.org/install-source/#gsc.tab=0

https://www.ufans.top/index.php/archives/370/

2026年7月9日 星期四

Glad and GLFW in Ubuntu

 1. Check previous article to install GLFW


2. Download Glad(https://glad.dav1d.de)

C/C++, OpenGL, gl(Version 3.3) --> Generate --> Download Zip file


3. File tree

├── glad.c

├── include/

│   ├── KHR/

│   │   └── khrplatform.h

│   └── glad/

│       └── glad.h

└── Hello_Window.cpp


4. Hello_World.cpp(A Sample code)

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

#include <glad/glad.h>

#include <GLFW/glfw3.h>

#include <iostream>


void framebuffer_size_callback(GLFWwindow* window, int width, int height) {

    glViewport(0, 0, width, height);

}


// Process escape key to close the window

void processInput(GLFWwindow *window) {

    if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {

        glfwSetWindowShouldClose(window, true);

    }

}


int main() {

    // 1. Initialize GLFW

    if (!glfwInit()) {

        std::cerr << "Failed to initialize GLFW" << std::endl;

        return -1;

    }


    // 2. Configure GLFW (Targeting OpenGL 3.3 Core Profile)

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);

    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

#ifdef __APPLE__

    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required for macOS

#endif


    // 3. Create the window object

    GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL Hello World", NULL, NULL);

    if (window == NULL) {

        std::cerr << "Failed to create GLFW window" << std::endl;

        glfwTerminate();

        return -1;

    }

    glfwMakeContextCurrent(window);

    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);


    // 4. Initialize GLAD before calling any OpenGL functions

    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {

        std::cerr << "Failed to initialize GLAD" << std::endl;

        return -1;

    }


    // 5. The Render Loop

    while (!glfwWindowShouldClose(window)) {

        // Input handling

        processInput(window);


        // Rendering commands (Clear screen with a dark greenish-blue color)

        glClearColor(0.2f, 0.3f, 0.3f, 1.0f);

        glClear(GL_COLOR_BUFFER_BIT);


        // Swap buffers and poll window events

        glfwSwapBuffers(window);

        glfwPollEvents();

    }


    // 6. Clean up resources

    glfwTerminate();

    return 0;

}

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


5. Build code

g++ Hello_World.cpp glad.c -I./include -lglfw -lGL -ldl -o Hello_Window



Hello GLFW in Ubuntu

 

1. install GLFW Library

sudo apt update

sudo apt install libglfw3 libglfw3-dev


2. Create a "Hello world.cpp" file and copy the under codes

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

#include <GLFW/glfw3.h>

#include <iostream>


int main() {

    // Initialize the library

    if (!glfwInit()) return -1;


    // Create a windowed mode window and its OpenGL context

    GLFWwindow* window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);

    if (!window) {

        glfwTerminate();

        return -1;

    }


    // Make the window's context current

    glfwMakeContextCurrent(window);


    // Loop until the user closes the window

    while (!glfwWindowShouldClose(window)) {

        // Render here

        glClear(GL_COLOR_BUFFER_BIT);


        // Swap front and back buffers

        glfwSwapBuffers(window);


        // Poll for and process events

        glfwPollEvents();

    }


    glfwTerminate();

    return 0;

}

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


3. Build code

g++ "Hello world.cpp" -o "Hello world" -lglfw -lGL


4. Run

./Hello\ world


5. Search GLFW version

apt show libglfw3-dev


2026年7月7日 星期二

FrameBuffer in Linux

如無效, 請在文字模式下(tty3),測試。 Ctrl+Alt+F3


1. 檢查:ls -l /dev/fb0

     crw-rw---- 1 root video 29, 0 Jul  7 15:53 /dev/fb0

2. 輸出擷取畫面:cat /dev/fb0 > screensnap

3. 檢查:ls -l sreensnap

4. 清理螢幕:clear

5. 寫入FrameBuffer:cat sreensnap > /dev/fb0

6. 恢復原狀:clear


參考網址:

Linux - FrameBuffer


2026年7月6日 星期一

Lambda Expression in C++, [=] (int x) mutable throw() -> int

 

支援條件:

=>GCC 4.5:需要指定 -std=c++11 參數。

=>Intel C++ Compiler 11:需要指定 /Qstd=c++0x 參數。

=>Microsoft Visual C++ 2010(包含在 Visual Studio 2010 之中)


語法如下:

[=] (int x) mutable throw() -> int {

    int n = x;

    return n;

}


各部件解說:

[=]:lambda-introducer,也稱為 capture clause。如何將目前 scope 範圍之變數抓至 lambda expression 中使用

(int x):lambda declarator,也稱為參數清單(parameter list)。定義此匿名函數的傳入參數列表。不需要傳入任何參數的話,可以連同小括號都一起省略。

mutable:mutable specification。可以讓 lambda expression 直接修改以傳值方式抓取進來的外部變數,若不需要此功能,則可以將其省略。

throw():例外狀況規格(exception specification)。指定該函數會丟出的例外。如果該函數沒有使用到例外的功能,則可以直接省略。

-> int:傳回值型別(return type)。如果定義的函數很單純,只包含一個傳回陳述式(statement)或是根本沒有傳回值的話,這部分就可以直接省略,讓編譯器自行判斷傳回值的型別。


重點參考:

[]:只有兩個中括號,完全不抓取外部的變數。

[=]:所有的變數都以傳值(by value)的方式抓取。

[&]:所有的變數都以傳參考(by reference)的方式抓取。

[x, &y]:x 變數使用傳值、y 變數使用傳參考。

[=, &y]:除了 y 變數使用傳參考之外,其餘的變數皆使用傳值的方式。

[&, x]:除了 x 變數使用傳值之外,其餘的變數皆使用傳參考的方式。

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

(int x)定義傳入參數列表,基本的用法跟一般函數的傳入參數列表一樣,不過多了一些限制條件:

    不可指定參數的預設值。

    不可使用可變長度的參數列表。

    參數列表不可以包含沒有命名的參數。



參考網址:

C++11 Lambda Expression

gcc與g++ 參數

[介紹]

gcc and g++分別是gnu的c & c++編譯器 gcc/g++在執行編譯工作的時候,總共需要4步: 

Preprocessing,Compilation,Assembling 和 Linking

1. Preprocessing(預處理): 展開 #include、#define → 得到 .i

2. Compilation(編譯): 把 .i 翻譯成組合語言 → 得到 .s

3. Assembling(組譯): 把 .s 轉成二進位的目標檔 → 得到 .o

4. Linking(連結): 連接目標代碼,生成可執行程序[鏈接器ld]


[參數]:

對於不同類型的參數,在排列上不需依任何順序。

兩個參數不可併成一個,如 -dr 這個參數便和 -d -r 在作用上有著極大的不同。

相同類型的參數,也沒有只能使用一個的限制。


-E:只作完 perprocess 便停止,不作接下來 compiler 等動作,並輸出到標準輸出 (stdout) 去,對於不需前置處理的檔案本參數無效。

  例子用法:

  gcc -E hello.c >; pianoapan.txt

  gcc -E hello.c | more

-S:只進行到 compiler 便停止,因此輸出為一組合語言檔。在內定的輸出檔名為輸入檔名去除 .c 或 .i 等字尾之後加上 .s 而成。

  例:gcc -S hello.c

  將生成.s的組合語言檔

-c:只 compile 或 assemble 輸入檔案,而不作連結,因此輸出為一目的檔 (object file),內定的檔名為去除 .c、.i 或是 .s 等之後加上 .o 而成。

  例:gcc -c hello.c

  將生成.o的obj文件

-o:設定輸出檔名;若沒此參數,會產生預設檔名 "a.out"。

  例:gcc -o hello hello.c


-pipe:在不同階段之編譯時,使用管線 (pipe) 取代暫存檔,在某些系統上的組譯程式 (assembler) 由於不能由管線讀取資料,而使得這參數無效,但對 GNU assembler 而言此參數當然可用。

  例:gcc -pipe -o hello hello.c

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

-imacros file:將file文件的Global,擴展到gcc/g++的輸入文件,Global定義本身並不出現在輸入文件中

-Dmacro:相當於C語言中的#define macro

-Dmacro=defn:相當於C語言中的#define macro=defn

-Umacro:相當於C語言中的#undef macro

-undef:取消對任何非標準宏(Global)的定義

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

-include file:包含某個代碼,簡單來說,就是便以某個文件,需 要另一個文件的時候,就可以用它設定,功能就相當於在代碼中使用#include<filename>

  例:gcc hello.c -include /root/pianopan.h

-Idir:對於用#include "file"時,gcc/g++會到-I制定的目錄查找,查找不到,然後將到系統的缺少的頭文件目錄查找。

-I-:就是取消前一個參數的功能,所以一般在-Idir之後使用

-idirafter dir:在-I的目錄裡面查找失敗,就到這個目錄裡面查找

-iprefix prefix, -iwithprefix dir:一般一起使用,當-I的目錄查找失敗,會到prefix+dir下查找

-nostdinc:使編譯器不再系統缺少的頭文件目錄裡面找頭文件,一般和-I聯合使用,明確限定頭文件的位置

-nostdin C++:規定不在g++指定的標準路經中搜索,但仍在其他路徑中搜索,此選項在創libg++庫使用

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

-llibrary:編譯時,使用的library

  例:gcc -lcurses hello.c

  使用ncurses庫編譯程序

-Ldir:制定編譯的時候,搜索library路徑。預設會找系統標準庫。

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

-lrt:Realtime Extensions Library

    用途:

        -lrt連結到即時函式庫(librt),提供與POSIX 即時擴展相關的功能。

        包含:timers, message queues, shared memory and semaphores

    常見功能:

        clock_gettime和clock_settime:取得和設定時鐘時間。

        mq_open和mq_close:操作POSIX 訊息佇列。

        shm_open和shm_unlink:操作POSIX 共享記憶體物件。

-lz:Zlib Compression Library

    用途:

        -lz連結到Zlib 庫,一個用於壓縮和解壓縮功能

    常見功能:

        compress和uncompress:用於資料的壓縮和解壓縮。

        deflate和inflate:用於stream壓縮和解壓縮。

-ldl:Dynamic Linking Library(動態連結函式庫)

    用途:

        -ldl連結到動態連結庫(libdl),提供了對動態庫(shared libraries)的載入和使用的支援。

        用於運行時動態載入、尋找符號和卸載共享庫。

    常見功能:

        dlopen:用於開啟一個動態庫。

        dlsym:用於在開啟的庫中尋找符號(即函數或變數)。

        dlclose:用於關閉開啟的庫。

-lanl:Asynchronous Name Lookup Library

    用途:

        -lanl連結到非同步名稱解析庫(libanl),提供非同步DNS 解析功能。

        提供非阻塞方式的主機名稱解析,以提高網路應用程式的效能。

    常見功能:

        getaddrinfo_a:異步獲取位址信息,用於非阻塞主機名稱解析。

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

-C:在預處理的時候,不刪除註釋信息,一般和-E使用,有時候分析程序

-M:生成文件關聯的信息。包含目標文件所依賴的所有源代碼你可以用gcc -M hello.c來測試一下,很簡單。

-MM:和上面的那個一樣,但是它將忽略由#include<file>; 造成的依賴關係。

-MD:和-M相同,但是輸出將導入到.d的文件裡面

-MMD:和-MM相同,但是輸出將導入到.d的文件裡面

-O0, -O1, -O2, -O3:編譯器的優化選項的4個級別,-O0表示沒有優化,-O1為缺少值,-O3優化級別最高

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

-g:產生作業系統認可格式 (native format) 的除錯碼 (可能為 stabs、COFF、XCOFF 或是 DWARF 之一),以便 GDB 除錯。

-ggdb:除了產生 native format 的除錯碼外,還再包含 GDB 專用的擴充部份。

-gstabs:產生 stabs 格式除錯碼,但不包含 GDB 的擴充部份,這是在大多數 BSD 系統上 DBX 所使用的格式,然而在 MIPS 和 Alpha 系統上卻會產生 DBX 所不能辨識的內嵌 (embedded) stabs 除錯碼。

-gstabs+:產生包含 GDB 擴充部份的 stabs 格式除錯碼,然而這樣別的除錯程式便無法用來除錯。

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

-static:此選項將禁止使用動態庫,所以,編譯出來的東西,一般都很大,也不需要什麼

動態連接庫,就可以運行.

-share:此選項將盡量使用動態庫,所以生成文件比較小,但是需要系統由動態庫.


-Wa,option:此選項傳遞option給彙編程序; 如果option中間有逗號,就將option分成多個選項,然後傳遞給會彙編程序

-Wl.option:此選項傳遞option給連接程序; 如果option中間有逗號,就將option分成多個選項,然後傳遞給會連接程序.

  例:-Wl,-soname,libmylib.so.1 

  與shared 函式庫,相關

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

 

請參考:

GCC指令參數

gcc.txt

[轉貼] 編織出個好程式--GCC參數篇(一)


2026年7月5日 星期日

gcc V.S. g++ (Compile in Linux)

 

GCC  V.S. gcc V.S. g++

GCC: 一整套由 GNU 開發的編譯器套装(GNU Compiler Collection),能編譯 C、C++、Fortran 等多種語言

gcc: GCC中的GUN C Compiler

g++: GCC中的GUN C++ Compiler


gcc調用C compiler,而g++調用C++ compiler


gcc和g++的主要區別

1.  對於*.c和*.cpp文件,gcc分別當做c和cpp文件編譯(c和cpp的語法強度是不一樣的)

2.  對於*.c和*.cpp文件,g++則統一當cpp檔編譯

3.  使用g++編譯檔案時,g++會自動連結標準函式庫STL,而gcc不會自動連結STL

4.  gcc在編譯C檔時,可使用的預定義巨集是比較少的

5.  gcc在編譯cpp檔時 / g++在編譯c檔和cpp檔時(gcc和g++呼叫的都是cpp檔的編譯器),會加入一些額外的巨集。

6. 在用gcc編譯c++檔時,為了能夠使用STL,需要加參數–lstdc++ ,但這並不代表gcc –lstdc++ 和g++等價,它們的差別不只是這個。


2026年7月2日 星期四

XnView MP in Ubuntu(Arm64)

 

1. Download XnView

    a. Enter: https://www.xnview.com/en/xnview-mp/

    b. Select and Download: Linux TGZ ARM 64bit

2. Decompress Application

    a. Decompress: XnView_MP-linux-arm64.tgz

3. Run Application

    a. ./xnview.sh


Some library(If you need):

1. libQt5Concurrent.so

sudo apt update

sudo apt install libqt5concurrent5


2. libQt5MultimediaWidgets

sudo apt update

sudo apt install libqt5multimediawidgets5


3. libQt5Xml.so.5

sudo apt update

sudo apt install libqt5xml5


Move to correct location:

1. sudo mv ./XnView /opt/

2. sudo cp /opt/XnView/XnView.desktop ~/Desktop


Visual Studio Core in Ubuntu

 

1. Download Visual Studio Core

a. Enter the website: https://code.visualstudio.com/download

b. Download .deb(x64) for Ubuntu


2. Install Visual Studio Core

a. In terminal

b. sudo dpkg -i code_1.127.0-1782814776_amd64.deb


3. start Visual Studio Core

a. In terminal: code or run Visual Studio Core in Apps


Reference:

Ubuntu 安裝 Visual Studio Code


Ubuntu支援繁體中文


Settings-->Region & Language-->Manage Installed Languages


Install / Remove Languages --> Check Chinese(Traditional) --> Apply

新酷音 by Fcitx5(Input Method Editor) in Ubuntu 22.04 LTS

 

Ubuntu 22.04預設IME(Input Method Editor) 是IBUS,也可安裝新酷音,但安裝後,一直無法切換語言,原因不明。


Linux還也另外一個IME(Input Method Editor)(Fcitx 5),也可安裝新酷音,安裝後,可切換輸入法。


安裝順序:

1. 確認 Fcitx5-chewing 已經在軟體資源庫

sudo apt search fcitx5-chewing

2. 安裝Fcitx5-chewing

sudo apt install fcitx5-chewing

3. 安裝必要套件

sudo apt install fcitx5 fcitx5-chinese-addons fcitx5-config-qt fcitx5-chewing

4. 更換IME-->Fcitx5

設定-->地區和語言-->管理安裝的語言-->鍵盤輸入法系統-->Fcitx 5



參考網頁:在 ubuntu 22.04 LTS 上用 Fcitx5 搭配新酷音