在xcode中调用C++第三方库Eigen

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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 值得学习的C语言开源项目 - 1. Webbench Webbench是一个在Linux下使用的非常简单的网站压测...
    tibet889阅读 14,823评论 1 144
  • C语言开源项目 Webbench Webbench是一个在linux下使用的非常简单的网站压测工具。它使用fork...
    残剑阅读 9,209评论 7 151
  • 沙子、飓风,鲜美的季节 可以轻柔毁灭一切稚嫩本身 我的躯体因为寒冷在痉挛 你在远方或在老树的分枝上栖息着 在黑色铅...
    白蕙侨阅读 1,760评论 0 2
  • 最近因为部门调整,我们部门活生生少了两个人,于是我跟部门小伙伴们开启了天天加班模式。 前天加班到十...
    心洁xinjie阅读 2,920评论 4 7
  • 四年前,我好不容易找到了一份工作,勉强进了一家保健品公司做宣传,所谓的宣传,就是编些蛊惑人的所谓软文。工资刚够糊口...
    王月冰阅读 1,841评论 0 3

友情链接更多精彩内容