笔记:C++ 中 NumCpp 的安装

1. 介绍

C++ 中 NumCpp 和 Python 中的 numpy 作用类似。



2.1 boost 库安装(NumCpp 库依赖于 boost 库,建议版本不需要太新,也不要太旧)
2.1.1 安装包

Web: https://www.boost.org/users/history/version_1_70_0.html

Version: https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.7z

2.1.2 安装
  1. 将安装包放在:

F:\Program Files\booat_C++

解压
在这里插入图片描述

  1. 进入:

F:\Program Files\booat_C++\boost_1_70_0

在这里插入图片描述

  1. 打开 VS 2019 点击 “工具”→“命令行”→“开发者 PowerShell§”

在这里插入图片描述

  1. 使用:
**********************************************************************
** Visual Studio 2019 Developer PowerShell v16.7.1
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************
PS D:\Computer\C++\Projects\firstDemo> cd 'F:\Program Files\booat_C++\boost_1_70_0'
PS F:\Program Files\booat_C++\boost_1_70_0>
  1. 运行 " .\bootstrap.bat"(等待一会)
PS F:\Program Files\booat_C++\boost_1_70_0> .\bootstrap.bat
Building Boost.Build engine

Generating Boost.Build configuration in project-config.jam for msvc...

Bootstrapping is done. To build, run:

    .\b2

To adjust configuration, edit 'project-config.jam'.
Further information:

    - Command line help:
    .\b2 --help

    - Getting started guide:
    http://boost.org/more/getting_started/windows.html

    - Boost.Build documentation:
    http://www.boost.org/build/

生成了几个文件夹,其中有一个 bjam.exe

PS F:\Program Files\booat_C++\boost_1_70_0> ls


    目录: F:\Program Files\booat_C++\boost_1_70_0


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         2020/11/9     16:09                bin.v2
d-----         2019/4/10      4:02                boost
d-----         2019/4/10      3:42                doc
d-----         2019/4/10      4:02                libs
d-----         2019/4/10      3:35                more
d-----         2020/11/9     16:03                stage
d-----         2019/4/10      3:35                status
d-----         2019/4/10      3:35                tools
-a----         2020/11/9     16:02         388608 b2.exe
-a----         2020/11/9     16:02         388608 bjam.exe
-a----         2019/4/10      3:35            850 boost-build.jam
-a----         2019/4/10      3:35            989 boost.css
-a----         2019/4/10      3:35           6308 boost.png
-a----         2019/4/10      3:35          19167 boostcpp.jam
-a----         2019/4/10      3:35           2997 bootstrap.bat
-a----         2020/11/9     16:02           3214 bootstrap.log
-a----         2019/4/10      3:35          10807 bootstrap.sh
-a----         2019/4/10      3:35            769 index.htm
-a----         2019/4/10      4:02           5567 index.html
-a----         2019/4/10      3:35            291 INSTALL
-a----         2019/4/10      3:35          11886 Jamroot
-a----         2019/4/10      3:35           1338 LICENSE_1_0.txt
-a----         2020/11/9     16:02            154 project-config.jam
-a----         2019/4/10      3:35            541 README.md
-a----         2019/4/10      3:35           2608 rst.css
  1. 最后执行(等待 4 – 5 分钟):
.\bjam.exe --toolset=msvc-14.1 architecture=x86 address-model=64 link=static --build-type=complete --with-system --with-thread --with-date_time --with-filesystem --with-serialization

会生成文件夹

.\stage\lib

  1. 在 VS 2019 中添加路径
    点击 “调试”→“调试属性”

在这里插入图片描述

选择 “VC++ 目录”,在 “包含目录” 和 “库目录” 分别添加路径“如图”

F:\Program Files\booat_C++\boost_1_70_0
F:\Program Files\booat_C++\boost_1_70_0\stage\lib

在这里插入图片描述

  1. 代码测试
#include <boost/lexical_cast.hpp>     
#include <iostream>   

using namespace std;
using namespace boost;

int main() {

	double a = lexical_cast<double>("3.1415926");
	string str = lexical_cast<string>("3.1415926");
	cout << "This is a number: " << a << endl;
	cout << "This is a string: " << str << endl;
	int b = 0;
	try {
		b = lexical_cast<int>("neo");
	}
	catch (bad_lexical_cast& e) {
		cout << e.what() << endl;
	}

	return 0;
}

在这里插入图片描述

成功



2.2 NumCpp 的下载使用
2.2.1 下载
git clone https://github.com/dpilger26/NumCpp.git
2.2.2 使用

将 NumCpp 文件下的 include 文件中的内容(红圈圈的两个)拷贝出来,放置在项目中(跟 main 函数同一级目录)

在这里插入图片描述

2.2.3 测试
#include <cstdio>
#include <iostream>
#include "include\\NumCpp.hpp"

int main() {
    
    nc::NdArray<int> a0 = { {1, 2}, {3, 4} };

    return 0;
}

可以通过就可以了

  • 6
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值