国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vscode編譯多文件復(fù)雜項目時tasks.json launch.json 的配置

這篇具有很好參考價值的文章主要介紹了vscode編譯多文件復(fù)雜項目時tasks.json launch.json 的配置。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。


前言

本文介紹了利用vscode編譯復(fù)雜工程的方法,包括gcc和cmke編譯時 tasks.json launch.json c_cpp_properties.json 的具體配置。


一、編譯代碼

使用例子
c/c++在windows下編譯:使用MinGW gcc從零編譯項目
vscode中tasks.json,c/c++編譯,vscode,編輯器,c++

二、g++配置tasks.json launch.json c_cpp_properties.json

tasks.json

編譯程序所需要的指令

{
    "tasks": [
        //下面兩條g++語句編譯動態(tài)庫
        {
            "type": "cppbuild",
            "label": "build_shared_step1", //相當(dāng)于這條g++語句的標(biāo)識
            "command": "/usr/bin/g++",  //編譯器安裝的完整路徑
            "args": [
                "-g","*.cpp","-c","-fPIC"  //相當(dāng)于/usr/bin/g++ -g *.cpp -c -fPIC 將當(dāng)前目錄下的所有.cpp文件都生成.o文件 
            ],
            "options": {
                "cwd": "${fileDirname}/../shared" //${fileDirname}為main函數(shù)所在目錄,意思是進(jìn)入到shared目錄
            },
            "group": "build"
        },
        {
            "type": "cppbuild",
            "label": "build_shared_step2",  //該條g++語句的標(biāo)識
            "command": "/usr/bin/g++",
            "args": [
                "-g","-shared","*.o","-o","../../lib/libmulti.so" //g++ -g -shared *.o -o ../../lib/libmuti.so 將當(dāng)前路徑的.o文件生成.so動態(tài)庫放入lib下
            ],
            "options": {
                "cwd": "${fileDirname}/../shared"  
            },
            "group": "build",
            "dependsOn": [  
                "build_shared_step1" //這條g++語句的執(zhí)行依賴于上一條g++的執(zhí)行
            ]
        },
        //下面兩條語句編譯靜態(tài)庫
        {
            "type": "cppbuild",
            "label": "build_static_step1",
            "command": "/usr/bin/gcc",
            "args": [
                "-g","*.cpp","-c"  // /usr/bin/gcc -g *.cpp -c 當(dāng)前目錄下的所有.cpp文件生成.o文件
            ],
            "options": {
                "cwd": "${fileDirname}/../static"  //進(jìn)入static目錄
            },
            "group": "build"
        },
        {
            "type": "cppbuild",
            "label": "build_static_step2",
            "command": "/usr/bin/ar",
            "args": [
                "rcs","../../lib/libadd.a","*.o"  // /usr/bin/ar rcs ../../lib/libadd.a *.o  將所有.o文件打包成靜態(tài)庫
            ],
            "options": {
                "cwd": "${fileDirname}/../static"
            },
            "group": "build",
            "dependsOn": [
                "build_static_step1"  //該條g++語句依賴于上一條g++語句生成的.o文件
            ]
        },
        //生成可執(zhí)行文件
        {
            "type": "cppbuild",
            "label": "build_main",  //生成可執(zhí)行程序命令名稱,launch.json會使用
            "command": "/usr/bin/g++",
            "args": [
                "-g","*.cpp","-o","../../bin/app","-I../../include",
                "-L../../lib","-lmulti","-ladd","-Wl,-rpath=../lib"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "group": "build",
            "dependsOn": [
                "build_shared_step2",  //可執(zhí)行文件生成依賴生成靜態(tài)庫和動態(tài)庫的g++語句
                "build_static_step2"
            ]
        }
    ],
    "version": "2.0.0"
}

上述tasks.json相當(dāng)于在腳本中執(zhí)行以下幾條命令

#生成動態(tài)庫
cd ${fileDirname}/../shared
/usr/bin/g++ -g *.cpp -c -fPIC
g++ -g -shared *.o -o ../../lib/libmuti.so
#生成靜態(tài)庫
cd ${fileDirname}/../static
/usr/bin/gcc -g *.cpp -c
/usr/bin/ar rcs ../../lib/libadd.a *.o
#生成可執(zhí)行文件
cd ${fileDirname}
/usr/bin/g++ -g *.cpp -o ../../bin/app -I../../include -L../../lib -lmulti -ladd -Wl,-rpath=../lib

每一條命令都要在tasks.json中的tasks中進(jìn)行配置,如果工程過大,就會顯得tasks.json非常臃腫和復(fù)雜,所以需要減少命令,可以通過編寫makefile 和cmake。

launch.json

配置可執(zhí)行程序的調(diào)試信息

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "aaaaa",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}/../../bin/app",  //tasks.json生成可執(zhí)行文件的路徑
      "args": [],  //可執(zhí)行文件需要的參數(shù)
      "stopAtEntry": false,  //是否在main函數(shù)處停住
      "cwd": "${fileDirname}/../../bin",  //進(jìn)入可執(zhí)行文件目錄
      "environment": [],
      "externalConsole": false,
      "MIMode": "gdb",
      "miDebuggerPath": "/usr/bin/gdb",  //gdb的完整路徑
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ],
      "miDebuggerArgs": "-q -ex quit; wait() { fg >/dev/null; }; /usr/bin/gdb -q --interpreter=mi",
      "preLaunchTask": "build_main"  //在調(diào)試前需要完成的任務(wù),這里是生成可執(zhí)行程序那條g++語句
    }
  ]
}

tasks.json和launch.json中的依賴關(guān)系如下圖:
vscode中tasks.json,c/c++編譯,vscode,編輯器,c++

c_cpp_properties.json

只在程序進(jìn)行展示的時候有用

{
  "configurations": [
    {
      "name": "linux-gcc-x64",
      "includePath": [
        "${workspaceFolder}/**"  //設(shè)置頭文件所在路徑,防止在打開程序是頭文件飄紅
      ],
      "compilerPath": "/usr/bin/gcc",
      "cStandard": "${default}",
      "cppStandard": "${default}",
      "intelliSenseMode": "linux-gcc-x64",
      "compilerArgs": [
        ""
      ]
    }
  ],
  "version": 4
}

三 cmake配置tasks.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "build_cmake",
            "command": "cmake",
            "args": [
                "-DCMAKE_INSTALL_PREFIX=${fileDirname}/../../install",
                " -DCMAKE_BUILD_TYPE=Release",
                " -DCMAKE_OS_ARCH=x86",
                "-DCMAKE_OS_TYPE=linux",
                "."
            ],
            "options": {
                "cwd": "${fileDirname}/../../"
            },
            "group": "build",
        },
        {
            "type": "cppbuild",
            "label": "build_make",
            "command": "make",
            "args": [],
            "options": {
                "cwd": "${fileDirname}/../../"
            },
            "group": "build",
            "dependsOn":[
                "build_cmake"  
            ]
        },
        {
            "type": "cppbuild",
            "label": "build_install",
            "command": "make",
            "args": ["install"],
            "options": {
                "cwd": "${fileDirname}/../../"
            },
            "group": "build",
            "dependsOn":[
                "build_cmake"  
            ]
        }
    ],
    "version": "2.0.0"
}

上面tasks.json相當(dāng)于如下三句指令:

cmake .   -DCMAKE_INSTALL_PREFIX=${fileDirname}/../../install  -DCMAKE_BUILD_TYPE=Release  -DCMAKE_OS_ARCH=x86 -DCMAKE_OS_TYPE=linux
make 
make install

四 調(diào)試代碼

在main.cpp界面點擊右上角如圖,出現(xiàn)如下界面:其中綠色的compilerun 點擊過后會報編譯錯誤,因為綠色的是編譯器默認(rèn)的tasks.json;如果我們是一個文件的程序,可以直接點三角形默認(rèn)生成tasks.json,這時就選擇ComlieRun進(jìn)行編譯。紅色的就會執(zhí)行我們修改后的tasks.json,Debug c/c++ File表示編譯運(yùn)行,但是不會在斷點處停留;Run C/C++ File 會編譯調(diào)試可執(zhí)行程序,并且會在斷點處停留。
vscode中tasks.json,c/c++編譯,vscode,編輯器,c++
點擊Debug C/C++出現(xiàn)如下界面,會展示tasks.json中的每一個任務(wù),紅色的就是我們tasks.json中的所有任務(wù),點擊對應(yīng)任務(wù)我們就能值編譯這一個任務(wù)。綠色的就是編輯器默認(rèn)的tasks.json這里并不存在,如果選擇就會編譯出錯。
vscode中tasks.json,c/c++編譯,vscode,編輯器,c++
我們將可執(zhí)行程序通過launch.json配置了調(diào)試信息,其中這條調(diào)試在launch.json中命名為aaaaa,我們點擊這一條就能對可執(zhí)行程序進(jìn)行調(diào)試了。
vscode中tasks.json,c/c++編譯,vscode,編輯器,c++
選擇 Debug c/c++ File -----> aaaaa 就能進(jìn)行斷點調(diào)試。
vscode中tasks.json,c/c++編譯,vscode,編輯器,c++

總結(jié)

vscode一鍵配置C/C++多個C及CPP文件編譯與tasks.json和launch.json原理文章來源地址http://www.zghlxwxcb.cn/news/detail-744978.html

到了這里,關(guān)于vscode編譯多文件復(fù)雜項目時tasks.json launch.json 的配置的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • tasks.json、launch.json、c_cpp_properties.json配置

    推薦內(nèi)容: https://blog.csdn.net/m0_70885101/article/details/131154332 https://blog.csdn.net/Zhouzi_heng/article/details/115014059 https://www.cnblogs.com/harrypotterisdead/p/14207866.html

    2024年02月06日
    瀏覽(17)
  • vscode debug 配置:launch.json

    打開新項目左邊的“運(yùn)行和調(diào)試” 點擊藍(lán)色字體“創(chuàng)建 launch.json 文件” 選擇上方“python” 選擇“Python 文件 調(diào)試當(dāng)前正在運(yùn)行的Python文件” 配置 launch.json 文件內(nèi)容: \\\"justMyCode\\\": true debug時只進(jìn)入項目自帶文件,不進(jìn)入安裝的包文件 \\\"env\\\": {\\\"PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT\\\": \\\"2\\\"} 多長

    2024年04月14日
    瀏覽(25)
  • 調(diào)試Dynaslam: Ubuntu系統(tǒng)下使用VS Code進(jìn)行自動化調(diào)試Dynaslam的教程,包括tasks.json和launch.json的配置

    調(diào)試Dynaslam: Ubuntu系統(tǒng)下使用VS Code進(jìn)行自動化調(diào)試Dynaslam的教程,包括tasks.json和launch.json的配置

    將 SET(CMAKE_BUILD_TYPE Release) 修改為 SET(CMAKE_BUILD_TYPE Debug) 不開啟編譯優(yōu)化,在編譯選項中包含 -g 參數(shù)來啟用調(diào)試符號,使調(diào)試器能夠準(zhǔn)確地設(shè)置斷點和跟蹤代碼。 將 cmake .. -DCMAKE_BUILD_TYPE=Release 替換為 cmake -DCMAKE_BUILD_TYPE=Debug .. 同時,將 DynaSLAM/Thirdparty/DBoW2/CMakeLists.txt 和 DynaSL

    2024年02月05日
    瀏覽(31)
  • CMake tasks.json launch.json

    CMake tasks.json launch.json

    launch.json(在.vscode文件夾中) tasks.json(在.vscode文件夾中) settings.json(在.vscode文件夾中) Gun.h? Gun.cpp Soldier.h Soldier.cpp CMakeLists.txt main.cpp 執(zhí)行結(jié)果:

    2024年01月20日
    瀏覽(46)
  • 自動更改由VSCode調(diào)試器創(chuàng)建的默認(rèn)launch.json文件

    自動更改由VSCode調(diào)試器創(chuàng)建的默認(rèn)launch.json文件

    File - Preference - Settings 修改下面的部分

    2024年02月20日
    瀏覽(18)
  • vscode調(diào)試debug,launch.json文件‘a(chǎn)rgs’無法發(fā)傳遞給腳本

    vscode調(diào)試debug,launch.json文件‘a(chǎn)rgs’無法發(fā)傳遞給腳本

    launch.json中的\\\"name\\\"參數(shù)不要隨便起,要與執(zhí)行的文件名一致! 參考鏈接:注意看鏈接帖子的評論

    2024年01月18日
    瀏覽(25)
  • cpp vocode launch.json 和 tasks.json

    cpp vocode launch.json 和 tasks.json

    在 VSCode 中配置 C++ 開發(fā)環(huán)境可以參考以下步驟: 安裝 C/C++ 擴(kuò)展:在 Extensions(擴(kuò)展)中搜索 C/C++ 并安裝。 安裝 MinGW-w64:MinGW-w64 是一個 Windows 下的 GCC 工具鏈,可以在 Windows 上開發(fā) C++ 程序??梢詮墓倬W(wǎng)下載 MinGW-w64 安裝包并安裝。安裝時需要注意選擇合適的架構(gòu)和版本并將

    2024年02月09日
    瀏覽(15)
  • windows .vscode的json文件配置 CMake 構(gòu)建項目 調(diào)試窗口中文設(shè)置等

    windows .vscode的json文件配置 CMake 構(gòu)建項目 調(diào)試窗口中文設(shè)置等

    一、CMake 和 mingw64的安裝和環(huán)境配置? 二、tasks.json和launch.json文件配置 tasks.json launch.json ?三、CMakeLists.txt文件 四、頭文件和源文件 cat.h cat.cpp main.cpp 五、中文亂碼問題解決 ?CMake C/C++程序輸出亂碼 Clion CMake C/C++程序輸出亂碼_cmake message 亂碼-CSDN博客https://blog.csdn.net/qq_37274323/

    2024年01月24日
    瀏覽(23)
  • vscode debug python launch.json添加args不起作用

    vscode debug python launch.json添加args不起作用

    為了帶入?yún)?shù)調(diào)試python 程序,按照網(wǎng)上搜到的教程配置了lauch.json文件,文件中添加了\\\"args\\\": [“model” “0” “path”] 但是點擊debug按鈕,并沒有讀取到launch文件中的args參數(shù),python中打印len(sys.argv)依然等于1。 參考:vscode-python 中的 issues vscode-doc: Python debugging in VS Code 簡單來說

    2024年02月09日
    瀏覽(28)
  • 【BUG解決】vscode debug python launch.json添加args不起作用

    為了帶入?yún)?shù)調(diào)試python 程序,點擊了ui界面右上角的debug按鈕,配置了lauch.json文件。按照網(wǎng)上搜到的教程添加了 \\\"args\\\": 但是點擊ui界面的debug按鈕,發(fā)現(xiàn)配置的參數(shù)并不起作用。 原因: 在 vscode-python 項目的issue和issue里找到答案。 省流:ui界面右上角的debug按鈕是一個擴(kuò)展插件

    2024年02月16日
    瀏覽(32)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包