Eigen是一个高层次的 C++ 库,有效支持线性代数,矩阵和矢量运算,数值分析及其相关的算法。近期整合的一个 C++ 项目使用了这个库,这个库没有静态库文件,使用起来略微麻烦。
网上很多人使用的是以下方式:
1. Install Homebrew
Package manager for Mac, allows you to download pretty much anything with one Terminal command. Follow steps here.
2. Install Eigen
Simply run the following command in Terminal: brew install eigen
Eigen is now installed.
Make note of the file path that is printed out on the command line! You will need that later and it can vary from person to person.
Homebrew saves Eigen files in /usr/local/include/eigen3/
3. Include Eigen files in your Xcode project’s Build Path
Open the project you want to use Eigen with.
Select your project’s build target under TARGETS
Select the Build Settings tab.
Scroll down to Apple LLVM 7.0 - Custom Compiler Flags Note that your version of the LLVM compiler may be different.
Double click the blank space to the right of Other C++ Flags.
Add the directory where Eigen files are located in the filepath you noted back in step 2 (-I <filepath>).
Search for HEADER_SEARCH_PATHS in your target build settings and add /usr/local/include/eigen3/ the same way you added the Eigen file path to OTHER_CPLUSPLUSFLAGS.
Your project should be able to use Eigen with no issues now.
实测编译会出错误
cannot specify -o when generating multiple output files
推荐使用下面的方式:
在官网下载Eigen文件,把下载文件中的Eigen、unsupported两个子文件夹拷贝到下面目录中:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
然后即可在工程中使用Eigen
附Eigen使用测试:
#include <iostream>
#include <Eigen/Dense>
using Eigen::MatrixXd;
int main()
{
MatrixXd m(2,2);
m(0,0) = 3;
m(1,0) = 2.5;
m(0,1) = -1;
m(1,1) = m(1,0) + m(0,1);
std::cout << m << std::endl;
}