CMake生成的可執行檔案能夠gdb除錯

2021-08-09 23:22:28 字數 670 閱讀 8020

採用 $ gdb   除錯時 出現 如下 錯誤:

(no debugging symbols found) 

set(cmake_build_type "debug") 

在下面加入:

set(cmake_cxx_flags_debug "$env -o0 -wall -g -ggdb")

set(cmake_cxx_flags_release "$env -o3 -wall")

原因是cmake 中有乙個變數 cmake_build_type ,可以的取值是 debug release relwithdebinfo >和 minsizerel。

當這個變數值為 debug 的時候,cmake 會使用變數 cmake_cxx_flags_debug 和 cmake_c_flags_debug 中的字串作為編譯選項生成 makefile;

$  cmake  -dcmake_build_type=debug    path               

注: path 為原始碼的資料夾路徑   ,  如果 需要 release 版  也可以  -dcmake_build_type = release

然後, 

$ cd  path 

$ make 

$ gdb  sample

注:sample 為該可執行檔案

生成可執行檔案過程

c語言編譯全過程 編譯的概念 編譯程式讀取源程式 字元流 對之進行詞法和語法的分析,將高階語言指令轉換為功能等效的彙編 再由匯程式設計序轉換為機器語言,並且按照作業系統對可執行檔案格式的要求鏈結生成可執行程式。編譯的完整過程 c源程式 預編譯處理 c 編譯 優化程式 s asm 匯程式設計序 obj...

pycharm生成可執行檔案

1.pycharm開啟terminal對話方塊 view tool windows terminal 2.安裝pyinstaller pip3 install pyinstaller 3.將py檔案轉換為相應作業系統可執行檔案 pyinstaller f onefile py 4.開啟py檔案所在的...

Python 生成可執行檔案

準備 開發環境python3 首先需要安裝第三方庫 pyinstaller pip直接安裝庫如果遇到各種問題,戳這裡 接下來 從shell中進入cmd視窗 import os os.system cmd 在cmd視窗中輸入 pyinstaller c f main.py 注 main.py是main...