Armadillo使用介绍(九):下载Armadillo、配置工程、运行第一个程序

一、下载Armadillo

通过以下两种途径下载Armadillo C++库源码:

  • Armadillo Download page
    如下图所示,可以下载到最新版本的armadillo库(随着时间变化,armadillo版本可能会比图示的版本更高)。
    Armadillo Download page图片
    点击上图红框中的链接后,会进入下图所示页面,自动下载源码。
    下载页面
  • Armadillo Gitlab page
    可以从Armadillo在Gitlab的仓库下载到最新的源码(Armadillo的仓库在Gitlab而非Github的原因,参见“What happened to the source code repository at GitHub ?”),具体步骤参见下图中的①->②->③
    Armadillo Gitlab page图片

二、配置工程

本节仅介绍Windows下采用visual studio搭建工程时应用Armadillo的方法,且仅支持win64版本。
对于配置类型为**应用程序(.exe)**的工程,采用以下配置方式:
2.1 前文下载的源码文件夹复制到解决方案路径下(宏命令表示为$(SolutionDir)
2.2 这里采用配置为Debug,平台为x64
2.3 “右键”->“属性”->“配置属性”->“C/C++”->“常规”->“附加包含目录”,新增值$(SolutionDir)armadillo\include;
附加包含目录
2.4 “链接器”->“常规”->“附加库目录”,新增值$(SolutionDir)armadillo\examples\lib_win64;
附加库目录
2.5 “链接器”->“输入”->“附加依赖项”,新增值lapack_win64_MT.lib;blas_win64_MT.lib;
附加依赖项
2.6 “生成事件”->“后期生成事件”->“命令行”,新增值copy $(SolutionDir)armadillo\examples\lib_win64\*.dll $(OutDir)
“生成事件”->“后期生成事件”->“说明”,新增值Copy .DLL to output directory(该步骤非必要,可选)
后期生成事件
对于上述配置的内容,配置完成后可以在工程的vcxproj文件中看到(见如下代码),一般命名格式为$(ProjectName).vcxproj(例如本示例的工程名称为ShortExample,则vcxproj文件为ShortExample.vcxproj)。

  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <SDLCheck>true</SDLCheck>
      <AdditionalIncludeDirectories>$(SolutionDir)armadillo\include;</AdditionalIncludeDirectories>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <AdditionalDependencies>lapack_win64_MT.lib;blas_win64_MT.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalLibraryDirectories>$(SolutionDir)armadillo\examples\lib_win64;</AdditionalLibraryDirectories>
    </Link>
    <PostBuildEvent>
      <Command>copy $(SolutionDir)armadillo\examples\lib_win64\*.dll $(OutDir)</Command>
    </PostBuildEvent>
    <PostBuildEvent>
      <Message>Copy .DLL to output directory</Message>
    </PostBuildEvent>
  </ItemDefinitionGroup>

三、运行第一个程序

源码
#include <iostream>
#include <armadillo>//包含armadillo头文件

using namespace std;
using namespace arma;//armadillo命名空间

int main()
{
	cout << "Armadillo version: " << arma_version::as_string() << endl;

	mat A = randu<mat>(4, 5);//4行5列矩阵
	mat B = randu<mat>(4, 5);

	cout << "A*B.t():\n" << A*B.t() << endl;//.t()向量或矩阵转置

	(A*B.t()).print("A*B.t():");

	system("pause");

	return 0;
}
运行结果
Armadillo version: 9.900.1 (Nocturnal Misbehaviour)
A*B.t():
   0.9536   1.0573   1.0669   0.9087
   0.3911   0.6334   0.6719   0.7834
   1.7734   2.6922   2.1078   2.4613
   0.8542   1.1044   0.8725   0.9546

A*B.t():
   0.9536   1.0573   1.0669   0.9087
   0.3911   0.6334   0.6719   0.7834
   1.7734   2.6922   2.1078   2.4613
   0.8542   1.1044   0.8725   0.9546
请按任意键继续. . .
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值