以下内容参见官方文档:

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: DebugReleaseMinRelSize, 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应用相关推荐

  1. 在Win10系统上使用VScode + Cmake配置C/C++开发环境,实现一键编译运行

    1.前言 前几天在公司的Ubuntu20.04电脑上配置了VSCode + Cmake的C/C++开发环境,可以用来跑跑C/C++的代码,然后,现在住的地方用的Windows,开发环境用的是 Visu ...

  2. ubuntu vscode通过cmake配置c++和VS2019一样 进行调试

    之前的 linux下vscode配置c++,使其和Visual Studio2019一样调试文章和本篇类似,配置vscode使其和vs2019进行调试和编译,但是之前的文章不是很实用,是通过命令行的形 ...

  3. VScode使用SSH连接Linux(Ubuntu)系统程序开发,详细教程

    VScode使用SSH连接Linux(Ubuntu)系统程序开发,详细教程 VScode使用SSH连接Linux(Ubuntu)系统程序开发 1.安装SSH 2.SSH连接远程服务器 3.远程编程开发 ...

  4. win命令安装 安装cmake_win10下VSCode+CMake+Clang+GCC环境搭建教程图解

    打算用C/C++把基本的数据结构与算法实现一遍, 为考研做准备, 因为只是想实现算法和数据结构, 就不太想用VisualStudio, 感觉VSCode不错, 遂在网上找了一些教程, 结合自己的需求, ...

  5. linux下julia的开发环境,Ubuntu搭建Julia远程开发环境

    Julia作为一门新兴的编程语言,还是可以学一学的,这里总结了一下Ubuntu系统远程搭建Julia开发环境的方法. 前期准备: 云服务器一台,操作系统为Ubuntu18.04, xshell6 + ...

  6. vscode 文件夹中查找_真香!使用 VSCode 进行远程开发调试

    对于大型的 Golang 项目往往我都会使用 Goland 这样的专业 IDE,但是由于我本地开发环境硬件资源偏低,不能很顺畅的使用 Goland,这个时候我们可以考虑使用 VSCode 来代替 Go ...

  7. Vscode+MobaXterm跨平台开发

    文章目录 跨平台开发 1. 开发工具 2. MobaXterm配置 2.1 配置SFTP目录跟随 2.2 MobaXterm下使用开发工具 3. VsCode配置 3.1 ubuntu 开启ssh服务 ...

  8. ubuntu vscode配置python3

    vscode 配置 python3开发环境_小兵大将0221-CSDN博客vscode来写python,配置灵活,界面美观,是个非常好的选择.我这里是在ubuntu系统下配置vscode的python ...

  9. ④ESP8266 开发学习笔记_By_GYC 【Ubuntu系统下ESP8266 开发环境搭建】

    目录 ④ESP8266 开发学习笔记_By_GYC [Ubuntu系统下ESP8266 开发环境搭建] 一.安装前准备 1.乐鑫官方的ESP-IDF 编程指南 2.ESP-IDF风格的ESP8266 ...

最新文章

  1. MFC给按钮添加皮肤
  2. 自学python需要下载什么软件-一个零基础学习Python应该知道的学习步骤与规划
  3. MyBatis Generator 详解
  4. JAVA-单例模式的几种实现方式
  5. 「Swift」笔记第二章 Basic Operators
  6. OCM_第十九天课程:Section9 —》Data Guard _ DATA GUARD 原理/DATA GUARD 应用/DATA GUARD 搭建...
  7. Membership Inference Attacks Against Recommender Systems论文解读
  8. 【方案分享】2021快手品牌号专项营销方案.pdf(附下载链接)
  9. 已解决:fastclick插件在IOS系统上点击input需要双击或长按才有效
  10. 最简单的视频编码器:基于libvpx(编码YUV为VP8)
  11. Savitzky-Golay 滤波器详解及matlab语言程序设计
  12. zend studio php 错误提示,Zend Studio错误总结,zendstudio总结_PHP教程
  13. MapGIS数据中心是什么?
  14. PRBTEK分享-关于示波器探头的11个错误认识
  15. css 文本排版方向,古文式排版等
  16. java整合kafka做消息消费
  17. win10笔记本外接显示器后,微信界面字体模糊问题的解决方案
  18. Py遇到Bad key “text.kerning_factor“ on line 4 in
  19. attention机制及self-attention(transformer)
  20. 【光通信】常见光模块与光纤收发器说明及作用区别

热门文章

  1. [USACO 08JAN]Haybale Guessing
  2. mysql数据库外连
  3. springMVC项目国际化(i18n)实现方法
  4. jQuery给动态添加的元素绑定事件的方法
  5. 附加到IIS进程调试页面
  6. 使用Bochs调试Linux内核初级入门
  7. C#字符串截取学习总结
  8. VC++网络资源集合
  9. struts 2 漏洞学习总结
  10. 11 mybatis-高级应用