简体   繁体   English

在C ++ Xcode中链接Armadillo库

[英]Linking Armadillo Library in C++ Xcode

I am new to Mac and also Armadillo. 我是Mac和Armadillo的新手。 Here's what I've done to use C++ with Armadillo. 这是我在Armadillo中使用C ++所做的工作。

  • Downloaded and installed Xcode 下载并安装Xcode
  • Downloaded and installed Homebrew 下载并安装Homebrew
  • In terminal typed "brew install armadillo" 在终端输入“ brew install armadillo”

Aside from that it's basically factory settings on the Mac. 除此之外,它基本上是Mac上的出厂设置。

Downloading armadillo seemed to work in brew, but I'm not really sure what to do next, because my code (shown below) still isn't compiling. 下载armadillo似乎可以在brew中工作,但我不确定下一步如何做,因为我的代码(如下所示)仍未编译。 It still says armadillo can't be found. 它仍然说找不到犰狳。

#include<iostream>
#include<armadillo>

using namespace std;
using namespace arma;

int main(int argc, const char * argv[]) {
   mat A;
   A << 1 << 2 << endr << 3 << 4 endr;
   cout << A << endl;

   return 0;
}

I know there's probably something simple I'm missing but I'm pretty new to all of it so I'd appreciate advice, thanks. 我知道可能缺少一些简单的东西,但是我对所有这些东西都很陌生,因此,我感谢您的建议,谢谢。

I used the default cmake options, so my armadillo.h .dylib ended up in /usr/local/include and /usr/local/lib, respectfully. 我使用了默认的cmake选项,因此我的armadillo.h .dylib分别出现在/ usr / local / include和/ usr / local / lib中。

1) Add the paths containing armadillo.h and the armadillo.5.20.2.dylib to Header Search Paths, and Library Search Paths. 1)将包含armadillo.h和armadillo.5.20.2.dylib的路径添加到“标题搜索路径”和“库搜索路径”。

Search Path Screenshot 搜索路径截图

The search dialog box is useful in locating the aforementioned project parameters. 搜索对话框在查找上述项目参数时很有用。

2) Add the dylab as a target dependency 2)将dylab添加为目标依赖项

Link Binary With Libraries Screenshot 将二进制文件与库链接起来屏幕截图

Click '+' -> Add Other -> ⌘ Shift G -> /usr/local 单击'+'->添加其他->⌘Shift G-> / usr / local

Then select /usr/local/lib/armadillo.5.20.2.dylib 然后选择/usr/local/lib/armadillo.5.20.2.dylib

In restrospect it is probably better to run cmake with an alternate install location such as: 在重新考虑的情况下,最好在备用安装位置运行cmake,例如:

cmake -DCMAKE_INSTALL_PREFIX:PATH=/opt

In which case the ⌘ Shift G step is unnecessary, and one can probably see the /opt directory from Finder by typing sudo SetFile -av /opt 在这种情况下,不需要⌘ Shift G步骤,并且可以通过键入sudo SetFile -av /opt从Finder中查看/ opt目录。

So I found out after searching around. 所以我在四处搜寻后才发现。 The fact that /usr/bin/ was hidden was really confusing me, but you can just cd there from the Terminal, I guess. /usr/bin/被隐藏的事实确实让我感到困惑,但是我想您可以从Terminal cd那里。 Then Armadillo was at the path /usr/local/Cellar/armadillo/4.600.2/include , which I copied into Search Paths -> Header Search Paths in Xcode. 然后Armadillo位于路径/usr/local/Cellar/armadillo/4.600.2/include ,我将其复制到Xcode中的Search Paths > Header Search Paths中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM