日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Ubuntu >内容正文

Ubuntu

ubuntu中使用VsCode+Eigen创建Eiegn应用程序

發布時間:2025/4/5 Ubuntu 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ubuntu中使用VsCode+Eigen创建Eiegn应用程序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Visual studio code是微軟發布的一個運行于 Mac OS X、Windows和 Linux 之上的,針對于編寫現代 Web 和云應用的跨平臺源代碼編輯器。

1. VsCode安裝

VScode官網下載.deb文件,網址鏈接如下:https://code.visualstudio.com/#alt-downloads

執行下面命令安裝VsCode: sudo dpkg -i code_1.48.2-1598353430_amd64.deb

在應用程序中搜索vscode可以看到已經安裝成功。

2. Vscode環境配置

2.1 安裝c/c++插件

通過左側的Extensions欄目安裝C/C++插件,這里我已經安裝。

2.2 建立工程

1. 由于VScode是以文件夾的形式管理工程的,因此我們首先新建一個文件夾,我這里取名叫eigen_VsCode,表示創建基于Vs_Code創建一個Eigen應用程序,文件夾內容是空的。

2. 使用VsCode打開文件夾eigen_VsCode,點擊左側的Explorer,然后點擊Open Folder。

3. 在eigen_VsCode目錄下新建.cpp文件,這里使用已經存在的eigenMatrix.cpp文件,如下所示:

2.3 更改配置文件(launch.json)

1. 點擊左側的Run, 點擊創建一個launch.json文件,C++(GDB/LLDB),將自動生成launch.json文件

2. 生成的默認launch.json文件如下。

3. 將默認launch.json修改成為如下,launch.json中各個字段的含義,后面學習中會逐個講解。

{
? ? // Use IntelliSense to learn about possible attributes.
? ? // Hover to view descriptions of existing attributes.
? ? // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
? ? "version": "0.2.0",
? ? "configurations": [
? ? ? ? {
? ? ? ? ? ? "name": "(gdb) 啟動",
? ? ? ? ? ? "type": "cppdbg",
? ? ? ? ? ? "request": "launch",
? ? ? ? ? ? "program": "${workspaceFolder}/${fileBasenameNoExtension}",
? ? ? ? ? ? "args": [],
? ? ? ? ? ? "stopAtEntry": false,
? ? ? ? ? ? "cwd": "${workspaceFolder}",
? ? ? ? ? ? "environment": [],
? ? ? ? ? ? "externalConsole": false,
? ? ? ? ? ? "MIMode": "gdb",
? ? ? ? ? ? "preLaunchTask": "build",
? ? ? ? ? ? "setupCommands": [
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? "description": "為 gdb 啟用整齊打印",
? ? ? ? ? ? ? ? ? ? "text": "-enable-pretty-printing",
? ? ? ? ? ? ? ? ? ? "ignoreFailures": true
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ]
? ? ? ? }
? ? ]
}

2.4 添加構建(編譯、鏈接等)任務(tasks.json)

為了方便在VScode里編譯C++代碼,我們可以將類似g++ -g main.cpp等g++命令寫入VScode的任務系統。首先,利用快捷鍵ctrl+shift+p打開命令行,輸入Tasks: Run task,會出現如下提示:

1. 選擇No Configured tasks. Configure Tasks...

2. 選擇Create task.json file from template

3. 選擇Others

4. 生成的默認tasks.json文件如下

這里的label為任務名,我們將”label"= "echo"改為”label"= "build"。由于我們的指令是g++,這里將”command“=”echo Hello“改為”command“=”g++“。然后添加g++的參數args。如果我們的g++指令為:g++ -g main.cpp,這里可以把參數設置為如下

如果我們想配置g++指令為:g++ -g main.cpp -std=c++11 -o main.out,則參數可設置為:

{
? ? // See https://go.microsoft.com/fwlink/?LinkId=733558
? ? // for the documentation about the tasks.json format
? ? "version": "2.0.0",
? ? "tasks": [
? ? ? ? {
? ? ? ? ? ? "label": "build",
? ? ? ? ? ? "type": "shell",
? ? ? ? ? ? "command": "g++",
? ? ? ? ? ? "args": ["-g", "${file}", "-std=c++11", "-o", "${fileBasenameNoExtension}"]
? ? ? ? }
? ? ]
}

2.5?添加配置庫文件支持

使用快捷鍵ctrl+shift+p調出命令行,選擇執行我們的build任務,但是發現build出現錯誤,提示:

?fatal error: Eigen/Core: 沒有那個文件或目錄
?#include <Eigen/Core>
? ? ? ? ? ^~~~~~~~~~~~
compilation terminated.

由于代碼中使用了eigen庫文件,需要配置包含庫文件路徑。ctrl+shift+p調出命令行,選擇C/C++: Edit Configurations(UI)

點擊c_cpp_properties.json打開配置文件。

配置如下:

我們只需要再紅框的 IncludePath 內加上需要的頭文件路徑即可,

這里提示下,常用庫的頭文件常見安裝位置如下:

  • /usr/include/
  • /usr/local/include

所以這兩個基本要加上的,如果你不知道你安裝的庫的頭文件在哪,但是知道關鍵的頭文件名稱,則可以用?locate?命令來查找:

locate?ros.h| grep include

這個命令的意思是查找所有ros.h的位置,并且找出路徑中帶有 include 字段的路徑。最終的c_cpp_properties.json配置如下:

{
? ? "configurations": [
? ? ? ? {
? ? ? ? ? ? "name": "Linux",
? ? ? ? ? ? "includePath": [
? ? ? ? ? ? ? ? "${workspaceFolder}/**",
? ? ? ? ? ? ? ? "/usr/include/",
? ? ? ? ? ? ? ? "/usr/local/include/",
? ? ? ? ? ? ? ? "/usr/include/eigen3/"
? ? ? ? ? ? ],
? ? ? ? ? ? "defines": [],
? ? ? ? ? ? "compilerPath": "/usr/bin/gcc",
? ? ? ? ? ? "cStandard": "c11",
? ? ? ? ? ? "cppStandard": "c++11",
? ? ? ? ? ? "intelliSenseMode": "clang-x64"
? ? ? ? }
? ? ],
? ? "version": 4
}

?

2.6 編譯

使用快捷鍵ctrl+shift+p調出命令行,選擇執行我們的build任務,生成eigenMatrix可執行文件。

?

2.7?調式運行

首先點擊產生斷點,然后啟動調式。

總結

以上是生活随笔為你收集整理的ubuntu中使用VsCode+Eigen创建Eiegn应用程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。