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

歡迎訪問 生活随笔!

生活随笔

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

Ubuntu

ubuntu+VsCode+Cmake+eigen 开发eigen应用

發布時間:2025/4/5 Ubuntu 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ubuntu+VsCode+Cmake+eigen 开发eigen应用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

以下內容參見官方文檔:

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

1. 安裝Cmake工具

點擊左側的Extensions,搜索Cmake tools,這里已經安裝。

2. 安裝Cmake

cmake --versioin

ubuntu系統已經安裝cmake, 如果沒有安裝cmake,請查閱資料在系統中安裝cmake.

3. 查看gcc是否安裝

gcc -v

如果沒有安裝gcc,則執行下面命令安裝:

sudo apt-get update sudo apt-get install build-essential gdb

?

4. 創建一個cmake工程

1. 新建一個空文件夾eigen_VsCode_cmake用于存放工程

2. 打開VsCode, 添加文件夾eigen_VsCode_cmake

3. 創建源文件和CMakeLists.txt文件

輸入快捷鍵Ctrl+Shift+P 運行?CMake: Quick Start?命令:

輸入工程名字:eigenMatrix

選擇可執行文件Executable。

生成.cpp和CMakeLists.txt文件如下所示。

可以看出CMakeLists.txt中project名字就是CMake: Quick Start階段輸入的名字eigenMatrix。

CMakeLists.txt文件:

cmake_minimum_required(VERSION 3.0.0)
project(eigenMatrix VERSION 0.1.0)

include(CTest)
enable_testing()

add_executable(eigenMatrix eigenMatrix.cpp)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

?

main.cpp修改為eigenMatrix.cpp 文件:

#include <iostream>
#include <ctime>
#include <eigen3/Eigen/Core>
#include <eigen3/Eigen/Dense>

using namespace std;
using namespace Eigen;

#define MATRIX_SIZE 50

int main(int argc, char *argv[])
{
? ? Eigen::Matrix<float, 2, 3, Eigen::ColMajor> matrix_23;
? ??
? ? Eigen::Vector3d v_3d;
? ??
? ? Eigen::Matrix3d matrix_33 = Eigen::Matrix3d::Zero();
? ??
? ? Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> matrix_dynamic;
? ??
? ? Eigen::MatrixXd matrix_x;
? ??
? ? matrix_23 << 1, 2, 3, 4, 5, 6;
? ? cout << "matrix_23:"<<endl;
? ? cout << matrix_23 << endl;
? ??
? ? cout << "matrix_23:" << endl;
? ? for (int i=0;i<2;++i){
? ? ? ? for (int j=0;j<3;++j){
? ? ? ? ? ? cout<<matrix_23(i,j)<<endl;
? ? ? ? }
? ? }
? ??
? ? v_3d << 1, 2,3;
? ??
? ? Eigen::Matrix<double, 2,1> result=matrix_23.cast<double>() * v_3d;
? ? cout<<"result:"<<endl;
? ? cout<<result<<endl;
? ??
? ? matrix_33 = Eigen::Matrix3d::Random();
? ? cout << "matrix_33:" <<endl;
? ? cout << matrix_33 <<endl;
? ??
? ? cout <<"matrix_33.transpose():"<<matrix_33.transpose() <<endl;
? ? cout <<"matrix_33.sum():"<<matrix_33.sum()<<endl;
? ? cout <<"matrix_33.trace():"<<matrix_33.trace()<<endl;
? ? cout <<"matrix_33 * 10"<<matrix_33 * 10<<endl;
? ? cout <<"matrix_33.inverse():"<<matrix_33.inverse()<<endl;
? ? cout<<"matrix_33.determinant():"<<matrix_33.determinant()<<endl;
? ??
? ? Eigen::SelfAdjointEigenSolver<Eigen::Matrix3d> eigen_slover(matrix_33.transpose()*matrix_33);
? ? cout<<"eigen_slover.eigenvalues():"<<eigen_slover.eigenvalues()<<endl;
? ? cout<<"eigen_slover.eigenvectors():"<<eigen_slover.eigenvectors()<<endl;
? ??
? ? Eigen::Matrix<double, MATRIX_SIZE, MATRIX_SIZE> matrix_NN;
? ? matrix_NN = Eigen::MatrixXd::Random(MATRIX_SIZE, MATRIX_SIZE);
? ? Eigen::Matrix<double, MATRIX_SIZE, 1> v_Nd;
? ? v_Nd = Eigen::MatrixXd::Random(MATRIX_SIZE, 1);
? ??
? ? clock_t time_stt=clock();
? ? Eigen::Matrix<double, MATRIX_SIZE, 1> x=matrix_NN.reverse()*v_Nd;
? ? cout<<"time use in normal invers is"<<1000*(clock()-time_stt)/(double)CLOCKS_PER_SEC<<"ms"<<endl;
? ??
? ? time_stt=clock();
? ? x=matrix_NN.colPivHouseholderQr().solve(v_Nd);
? ? cout<<"time use in Qr compsition is"<<1000*(clock()-time_stt)/(double)CLOCKS_PER_SEC<<"ms"<<endl;
? ??
? ??
? ? return 0;
}

?

5. 選擇編譯工具CMake: Select a Kit(toolchain

Ctrl+Shift+P -》CMake: Select a Kit? 選擇編譯工具鏈

選擇GCC for x86_64-linux-gnu 7.5.0

VsCode窗口最下面顯示當前的編譯器,可以點擊修改toolchain。

?

6. 選擇variant,通常說的debug或者release

A variant contains instructions for how to build your project. By default, the CMake Tools extension provides four variants, each corresponding to a default build type:?Debug,?Release,?MinRelSize, and?RelWithDebInfo. These options do the following:

Debug: disables optimizations and includes debug info.?Release?: Includes optimizations but no debug info.?MinRelSize?: Optimizes for size. No debug info.?RelWithDebInfo?: Optimizes for speed and includes debug info.

To select a variant, open the Command Palette (Ctrl+Shift+P) run the?CMake: Select Variant?command.

Select?Debug?to include debug information with your build.

The selected variant will appear in the Status bar next to the active kit.

?

7. CMake: Configure 根據kit和variant生成配置文件

Now that you've selected a kit and a variant, open the Command Palette (Ctrl+Shift+P) and run the?CMake: Configure?command to configure your project. This generates build files in the project's build folder using the kit and variant you selected.

?

8. Build eigenMatrix編譯工程

After configuring your project, you're ready to build. Open the Command Palette (Ctrl+Shift+P) and run the?CMake: Build?command, or select the?Build?button from the Status bar.

You can select which targets you'd like to build by selecting?CMake: Set Build Target?from the Command Palette. By default, CMake Tools builds all targets. The selected target will appear in the Status bar next to the?Build?button.

?

9.Debug eigenMatrix調試工程

在代碼中添加斷點

Ctrl+Shift+P-》CMake: Debug

停留在調試的斷點處

?

總結

以上是生活随笔為你收集整理的ubuntu+VsCode+Cmake+eigen 开发eigen应用的全部內容,希望文章能夠幫你解決所遇到的問題。

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