在WINDOWS中安装使用SIGPACK(MinGW64+Sublime Text3 &Visual Studio)
本文介绍在Windows下安装使用SigPack库,涉及Armadillo、OpenBLAS安装使用说明,最终实现对SigPack示例CPP基于MinGW64在Sublime Text3下的编译运行,并对在VS中的使用做了部分示例。
目录
一、SIGPACK简介
二、在WINDOWS下安装介绍
三、安装OpenBALS
四、安装Armadillo
五、安装SigPack
一、SIGPACK简介
(官方介绍,不做累述)
SigPack - the C++ signal processing library
SigPack - general
SigPack is a C++ signal processing library using the library Armadilloas a base. The API will be familiar for those who has used IT++ and Octave/Matlab. The intention is to keep it small and only implement the fundamental signal processing algorithms.
SigPack - features
- Easy to use, based on Armadillo library
- API similar to Matlab/Octave and IT++
- FIR/IIR filter
- Window functions - Hanning, Hamming, Bartlett, Kaiser ...
- Spectrum and spectrogram
- Timing/Delay
- Gnuplot support
- Up/Downsampling
- Config file parser
- FFTW 1-D and 2-D support
- Simple image I/O functions for pbm, pgm and ppm format
- Adaptive FIR filters - LMS, N-LMS, RLS, Kalman and Newton
- Linear, Extended and Unscented Kalman filters and RTS smoothers
Download and installation
Download Armadilloand SigPackand install/extract them to your install directory. I recommend OpenBLASand FFTW installed from source to get the optimum performance.
For Windows 64bit users: make sure your path to the .lib and .dll files are updated in your environment variables. Armadillo have some prebuilt libs at <install dir>\examples\lib_win64
二、在WINDOWS下安装介绍
SIGPACK需用到Armadillo、OpenBLAS、FFTW等,打开Armadillo介绍,会发现,它需要BLAS和LAPACK库,或者OpenBLAS库,因此,首先应该考虑安装OpenBLAS库,然后再安装Armadillo库,然后再安装SIGPACK库,进行测试使用。
三、安装OpenBALS
OpenBLAS是高性能多核BLAS库,是GotoBLAS2 1.13 BSD版本的衍生版。项目主页是 https://github.com/xianyi/OpenBLAS。
另可参考:
l 矩阵运算库Armadillo,Eigen,MATCOM在windows+vs2010环境下的安装和测评
1、下载安装OpenBLAS,发现其需要pkg-config,下载并添加其bin目录到系统路径中。
Step-by-step procedure to get pkg-config working on Windows:
MinGW was installed to C:\MinGW. There were multiple versions of the packages available, downloaded the latest version.
- go to http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/ OR http://ftp.gnome.org/pub/gnome/binaries/win64/dependencies/
- download the file pkg-config_0.26-1_win32.zip OR pkg-config_0.23-2_win64.zip
- extract the file bin/pkg-config.exe to C:\MinGW\bin OR your GNU bin path
- download the file gettext-runtime_0.18.1.1-2_win32.zip OR gettext-runtime_0.18.1.1-2_win64.zip
- extract the file bin/intl.dll (OR libintl-8.dll)to C:\MinGW\bin
- go to http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.28 OR http://ftp.gnome.org/pub/gnome/binaries/win64/glib/2.26/
- download the file glib_2.28.8-1_win32.zip OR glib_2.26.1-1_win64.zip
- extract the file bin/libglib-2.0-0.dll to C:\MinGW\bin
Now CMake will be able to use pkg-config if it is configured to use MinGW.
2、还需要gawk和sed,在GNUwin32中有,下载bin版即可
https://sourceforge.net/projects/gnuwin32/files/
SED: https://sourceforge.net/projects/gnuwin32/files/sed/4.2.1/sed-4.2.1-bin.zip/download;
AND https://sourceforge.net/projects/gnuwin32/files/sed/4.2.1/sed-4.2.1-dep.zip/download
GAWK: https://sourceforge.net/projects/gnuwin32/files/gawk/3.1.6-1/gawk-3.1.6-1-bin.zip/download
解压后,将bin中的文件放在你的GNU bin目录中,然后,将bin路径添加到系统路径中。
3、下载OpenBLAS源码,编译生成动态库和静态库,添加路径到系统PATH中。
- 方法1—用CMAKE+VS编译OpenBLAS动态库
用CMAKE对OpenBLAS源码按目录外方式生成VS项目解决方案,对ALL BUILD进行debug和release用win64方式生成,成功后得到libopenblas.dll、libopenblas.lib等文件,用于在VS项目中调用,官方文档说明此方式编译生成的库文件,仅DLL库可用,但需要进行一些加载设置。对此,经测试,在VS2015下新建空控制台项目测试,针对项目属性进行配置:C/C++——常规——附加包含目录:<OpenBLAS install dir>\include;链接器——输入——附加依赖项:<OpenBLAS build dir>\lib\RELEASE\libopenblas.lib 或者 <OpenBLAS build dir>\lib\DEBUG\libopenblas.lib,可以在x64方式正常调用并通过编译。
- 方法2—用MinGW编译OpenBLAS静态库和动态库
- Install the MinGW (GCC) compiler suite, either 32-bit (http://www.mingw.org/) or 64-bit (http://mingw-w64.sourceforge.net/). In addition, please install MSYS with MinGW.
- Build OpenBLAS in the MSYS shell. Usually, you can just type "make". OpenBLAS will detect the compiler and CPU automatically. Download [msys binary packages]
- After the build is complete, OpenBLAS will generate the static library "libopenblas.a" and the shared dll library "libopenblas.dll" in the folder. You can type "make PREFIX=/your/installation/path install" to install the library to a certain location.
Generate import library (0.2.10 and after version),OpenBLAS already generated the import library "libopenblas.dll.a" for "libopenblas.dll".
4、Using the library
- Link shared library
gcc -o test test.c -I /your_path/OpenBLAS/include/ -L/your_path/OpenBLAS/lib -lopenblas
If the library is multithreaded, please add -lpthread. If the library contains LAPACK functions, please add -lgfortran or other Fortran libs.
- Link static library
gcc -o test test.c /your/path/libopenblas.a
You can download test.c from https://gist.github.com/xianyi/5780018
5、Code examples
Call CBLAS interface
This example shows calling cblas_dgemm in C. https://gist.github.com/xianyi/6930656
#include <cblas.h>
#include <stdio.h>
int main()
{
int i=0;
double A[6] = {1.0,2.0,1.0,-3.0,4.0,-1.0};
double B[6] = {1.0,2.0,1.0,-3.0,4.0,-1.0};
double C[9] = {.5,.5,.5,.5,.5,.5,.5,.5,.5};
cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans,3,3,2,1,A, 3, B, 3,2,C,3);
for(i=0; i<9; i++) printf("%lf ", C[i]);
printf("\n");
return 0;
// Expected output: 11.000000 -9.000000 5.000000 -9.000000 21.000000 -1.000000 5.000000 -1.000000 3.000000
}
gcc -o test_cblas_open test_cblas_dgemm.c -I /your_path/OpenBLAS/include/ -L/your_path/OpenBLAS/lib -lopenblas -lpthread -lgfortran
- 附:使用Sublime Text3编译使用了OpenBLAS库的C源程序,可以在ST3新建一个编译环境文件,复制粘贴下面内容,并对其中引用的路径修改为正确路径,即可在ST3中进行编译使用了。
// Put this file ([Your Build Name].sublime-build) here:
// "C:\Users\[User Name]\AppData\Roaming\Sublime Text 3\Packages\User"
// Use "Ctrl+B" to Build and "Crtl+Shift+B" to Build or Run the project.
// OR use "Tools -> Build System -> New Build System..." and put the code there.
{
//用GCC编译C程序,支持MinGW编译C文件使用了OpenBLAS库,命名为GCCOpenBLAS.sublime-build
"shell_cmd": "gcc \"${file}\" -o \"${file_path}/${file_base_name}\" -I \"c:/OpenBLAS/include/\" -L\"c:/OpenBLAS/lib\" -lopenblas -lpthread -lgfortran",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c",
"shell": true,
"variants":
[
{
"name": "Run",
"shell_cmd": "gcc \"${file}\" -o \"${file_path}/${file_base_name}\" -I \"c:/OpenBLAS/include/\" -L\"c:/OpenBLAS/lib\" -lopenblas -lpthread -lgfortran && start cmd /c \"\"${file_path}/${file_base_name}\" & pause\""
}
]
//命令行GCC
//gcc -o file_base_name file_name.c -I c:/OpenBLAS/include/ -Lc:/OpenBLAS/lib -lopenblas -lpthread -lgfortran
}
四、安装Armadillo
参考:How to use Armadillo on Windows
Getting started with Armadillo a C++ Linear Algebra Library on Windows, Mac and Linux
Armadillo is a C++ template library for linear algebra. It is built upon LAPACK and BLAS. It offers a simple API that is similar to that of Matlab.
1. Download the source code of Armadillo from here . Unzip the source code of Armadillo to a directory.
2. Create an environment variable named ARMADILLO_ROOT with a value of the Armadillo directory.
3. Armadillo requires LAPACK and BLAS libraries for any non-trivial matrix operation. To enable it to use these libraries, open $(ARMADILLO_ROOT)/include/armadillo_bits/config.hpp and uncomment the defines of ARMA_USE_LAPACK and ARMA_USE_BLAS.
- 使用方法1—基于VC++或VS
4. To use Armadillo in your Visual C++ project, add $(ARMADILLO_ROOT)/include as an Include directory.
5. Since Armadillo source code uses LAPACK and BLAS, your project needs to link with these libraries. Armadillo ships with pre-built 32-bit .lib and .dll files for LAPACK and BLAS. Add $(ARMADILLO_ROOT)/examples/lib_win32 as Library directory to your project. Add blas_win32_MT.lib and lapack_win32_MT.lib as additional dependencies to your project.
6. Include the armadillo header file in your source code. Use the Armadillo classes and methods in your code. Remember to use the namespace arma:: Your code should compile to an EXE file without any further problems.
7. Copy the blas_win32_MT.dll and lapack_win32_MT.dll files from $(ARMADILLO_ROOT)/examples/lib_win32 to the directory that contains your EXE file. Your program should execute successfully now.
- 使用方法2—基于MinGW的g++
4. 因为编译生成静态库,所以无法使用"-larmadillo"参数生成,可用其示例中已编译好的BLAS和LAPACK库(新的版本中都是基于win64编译的,对应文件为${ARMADILLO_ROOT}\examples\lib_win64\blas_win64_MT和lapack_win64_MT)和OpenBLAS一起使用,来替换"-larmadillo"参数。
5、在具体编译项目CPP时,将${ARMADILLO_ROOT}\examples\lib_win64\目录下的blas_win64_MT.dll和lapack_win64_MT.dll复制到项目CPP同目录下,或者将${ARMADILLO_ROOT}\examples\lib_win64目录添加到系统PATH中。
6、在g++命令行中添加“-IC:/Armadillo/include -IC:/OpenBLAS/include -LC:/OpenBLAS/lib -LC:/Armadillo/examples/lib_win64 -llapack_win64_MT -lopenblas -lpthread -lgfortran”参数,即可通过编译了。
- 示例代码(详见本节参考链接2):
#include <iostream>
#include <armadillo> int main(int argc, const char **argv) {
// Initialize the random generator
arma::arma_rng::set_seed_random(); // Create a 4x4 random matrix and print it on the screen
arma::Mat<double> A = arma::randu(, );
std::cout << "A:\n" << A << "\n"; // Multiply A with his transpose:
std::cout << "A * A.t() =\n";
std::cout << A * A.t() << "\n"; // Access/Modify rows and columns from the array:
A.row() = A.row() + A.row();
A.col().zeros();
std::cout << "add rows 1 and 3, store result in row 0, also fill 4th column with zeros:\n";
std::cout << "A:\n" << A << "\n"; // Create a new diagonal matrix using the main diagonal of A:
arma::Mat<double>B = arma::diagmat(A);
std::cout << "B:\n" << B << "\n"; // Save matrices A and B:
A.save("A_mat.txt", arma::arma_ascii);
B.save("B_mat.txt", arma::arma_ascii); system("pause");
return ;
}
运行结果示例:
五、安装SigPack
1、下载SigPack,在自定义目录解压。
2、下载Gnuplot,因在SigPack的示例中要用到二维图形显示,需要此库。添加<gnuplot install dir>\bin目录到系统PATH中即可。
3、下载FFTW (Precompiled FFTW Windows DLLs),用于计算离散傅里叶变换(DFT)的C语言开源库,将.zip压缩包解压到< FFTW install dir >,如果需要针对VS的静态库,可使用lib.exe(windows自带的有)对目录中.def生成.lib文件(针对64位系统需要添加“/machine:x64”参数),如:
针对32-bit:
lib /def:libfftw3-3.def
lib /def:libfftw3f-3.def
lib /def:libfftw3l-3.def
针对64-bit:
lib /machine:x64 /def:libfftw3-3.def
lib /machine:x64 /def:libfftw3f-3.def
lib /machine:x64 /def:libfftw3l-3.def
针对MinGW的静态库生成,使用MinGW提供的DLLTOOL命令对.def生成.a文件,如:(生成libfftw3.a后可在g++编译参数中直接使用“-lbfftw3”参数,否则会提示找不到此库)
dlltool -d libfftw3-3.def -l libfftw3.a
dlltool -d libfftw3f-3.def -l libfftw3f.a
dlltool -d libfftw3l-3.def -l libfftw3l.a
然后在使用g++进行编译时添加“-L< FFTW install dir >”及“-lbfftw3”参数即可实现对FFTW库的调用了。
4、在用g++对项目CPP进行编译时,添加“-I<SigPack install dir>/sigpack”参数即可。
5、对demo_c++目录下的示例CPP进行编译,可使用如下命令:
g++ -o sp_demo_112 sp_demo_112.cpp -IC:/Armadillo/include -IC:/SigPack -IC:/OpenBLAS/include -LC:/OpenBLAS/lib -LC:/Armadillo/examples/lib_win64 -LC:/FFTW64 -llapack_win64_MT -lbfftw3 -lopenblas -lpthread -lgfortran
附:使用Sublime Text3编译使用了SigPack库的CPP源程序,可以在ST3新建一个编译环境文件,复制粘贴下面内容,并对其中引用的路径修改为正确路径,即可在ST3中进行编译使用了。
// Put this file ([Your Build Name].sublime-build) here:
// "C:\Users\[User Name]\AppData\Roaming\Sublime Text 3\Packages\User"
// Use "Ctrl+B" to Build and "Crtl+Shift+B" to Build or Run the project.
// OR use "Tools -> Build System -> New Build System..."
{
//用GCC编译C程序,支持MinGW编译C文件使用了OpenBLAS库,命名为GCCOpenBLAS.sublime-build
"shell_cmd": "g++ -o \"${file_path}/${file_base_name}\" \"${file}\" -I\"C:/Armadillo/include\" -I\"C:/SigPack\" -I\"C:/OpenBLAS/include\" -L\"C:/OpenBLAS/lib\" -L\"C:/Armadillo/examples/lib_win64\" -L\"C:/FFTW64\" -llapack_win64_MT -lfftw3 -lopenblas -lpthread -lgfortran",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[
{
"name": "Run",
"shell_cmd": "g++ -o \"${file_path}/${file_base_name}\" \"${file}\" -I\"C:/Armadillo/include\" -I\"C:/SigPack\" -I\"C:/OpenBLAS/include\" -L\"C:/OpenBLAS/lib\" -L\"C:/Armadillo/examples/lib_win64\" -L\"C:/FFTW64\" -llapack_win64_MT -lfftw3 -lopenblas -lpthread -lgfortran && start cmd /c \"\"${file_path}/${file_base_name}\" & pause\""
}
]
//命令行GCC
//g++ -o sp_demo_112 sp_demo_112.cpp -IC:/Armadillo/include -IC:/SigPack -IC:/OpenBLAS/include -LC:/OpenBLAS/lib -LC:/Armadillo/examples/lib_win64 -llapack_win64_MT -lopenblas -lpthread –lgfortran
}
(本文部分内容来源于网络,感谢原文作者分享。)
在WINDOWS中安装使用SIGPACK(MinGW64+Sublime Text3 &Visual Studio)的更多相关文章
- 在WINDOWS中安装使用GSL(MinGW64+Sublime Text3 & Visual Studio)
本文介绍在Windows下安装使用GSL库,涉及GSL两个版本(官方最新版及GSL1.8 VC版).msys shell.GCC.G++等内容,最终实现对GSL安装及示例基于MinGW64在Subli ...
- 在Windows中安装MinGW-w64(有图,一步一步)
在Windows中安装MinGW-w64 发表回复 如需配合Sublime Text 3编译C程序, 请参考本站文章: 使用Sublime Text 3与MinGW-w64编译C语言程序 MinGW, ...
- 怎样把windows中安装的程序列出来?
症状/问题我怎样把windows中安装的程序信息输出到一个文本文件中?解决方法使用 windows 操作系统中的命令:wmic就可以做到.下面的命令就可以把系统中安装的程序都输出到文件ProgramL ...
- windows中安装python
windows中安装python 在windows中安装python的步骤如下. 1.下载python的安装包 python的安装包地址为: https://www.python.org/ftp/py ...
- 在Windows中安装PostgreSQL
在Windows中安装PostgreSQL 虽然PostgreSQL是为类UNIX平台开发的,但它却是可以移植的.从7.1版本开始,PostgreSQL可以编译安装和作为一个PostgreSQL服务器 ...
- Windows中安装Scrapy
在linux中安装Scrapy只需要导入一些非python的支持包,在windows中安装Scrapy则是一波三折. 总之来说,主要分为以下几个步骤,可能由于系统问题(国内个人机子,甚至是小企业的机子 ...
- 下载文件时-修改文件名字 Redis在Windows中安装方法 SVN安装和使用(简单版) WinForm-SQL查询避免UI卡死 Asp.Net MVC Https设置
下载文件时-修改文件名字 1后台代码 /// <summary> /// 文件下载2 /// </summary> /// <param name="Fil ...
- Python原来这么好学-1.1节: 在windows中安装Python
这是一本教同学们彻底学通Python的高质量学习教程,认真地学习每一章节的内容,每天只需学好一节,帮助你成为一名卓越的Python程序员: 本教程面向的是零编程基础的同学,非科班人士,以及有一定编程水 ...
- 在Windows中安装PySpark环境
在Windows中安装PySpark环境 安装Python 可以选择安装官方版本的Python,或是Anaconda,对应的地址如下. 下载地址 Python:https://www.python.o ...
随机推荐
- js根据毫米/厘米算像素px
<html><meta http-equiv="content-type" content="text/html;charset=utf-8" ...
- IDEA2019激活码集合(非盈利)
56ZS5PQ1RF-eyJsaWNlbnNlSWQiOiI1NlpTNVBRMVJGIiwibGljZW5zZWVOYW1lIjoi5q2j54mI5o6I5p2DIC4iLCJhc3NpZ25lZ ...
- idea中pom.xml添加了新的maven依赖,点击import changes没反应
打开file,setting. 选择Build,Execution,Deployment -> Build Tools -> Maven. 修改maven home directory为自 ...
- java基础 关于转换流
转换流有两种:InputStreamReader:将字节流转换为字符流 OutputStreamWriter:将字符流转换为字节流 什么时候使用转换流?由以下分析: 流对象很多,首先要明确那个流对象. ...
- text-stroke实现文字描边(镂空)、text-fill-color实现文字填充&渐变(+animation实现流光字体)
text-stroke:<' text-stroke-width '> || <' text-stroke-color '>(text-stroke-width:设置或检索对象 ...
- Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) B. Weakened Common Divis
题目链接 让你找一个数,使得这个数,可以被每个二元组的两个数中的一个数整除. 先将第一个二元组的两个数质因数分解一下,分解的质数加入set中,然后,对剩下的n-1个二元组进行遍历,每次遍历到的二元组对 ...
- Scanner输入数字时个位十位百位千位单独取出。
Scanner inn = new Scanner(System.in); int i = inn.nextInt(); System.out.println("个位是"+i%10 ...
- python&django 实现页面中关联查询小功能(中级篇)
目的 组合搜索实现如下图功能 知识点 1.使用自定义标签模板(templatetags) 实现 models.py 和 views.py和初级篇一样 重点如下:在app01目录下创建templatet ...
- spring boot集成websocket实现聊天功能和监控功能
本文参考了这位兄台的文章: https://blog.csdn.net/ffj0721/article/details/82630134 项目源码url: https://github.com/zhz ...
- 20175204 张湲祯 2018-2019-2《Java程序设计》
Arrays和String单元测试 一.类的作用 1.- String类 charAt String的charAt的作用是将字符串中第i个位置上的字符(从0开始计数)赋值给n,其用法为n=string ...