Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking Armadillo Library in C++ Xcode

I am new to Mac and also Armadillo. Here's what I've done to use C++ with Armadillo.

  • Downloaded and installed Xcode
  • Downloaded and installed Homebrew
  • In terminal typed "brew install armadillo"

Aside from that it's basically factory settings on the 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. 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.

like image 703
Paradox Avatar asked Apr 15 '26 15:04

Paradox


2 Answers

I used the default cmake options, so my armadillo.h .dylib ended up in /usr/local/include and /usr/local/lib, respectfully.

1) Add the paths containing armadillo.h and the armadillo.5.20.2.dylib to Header Search Paths, and Library Search Paths.

Search Path Screenshot

The search dialog box is useful in locating the aforementioned project parameters.

2) Add the dylab as a target dependency

Link Binary With Libraries Screenshot

Click '+' -> Add Other -> ⌘ Shift G -> /usr/local

Then select /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 -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 -a v /opt

like image 101
mpeaton Avatar answered Apr 17 '26 06:04

mpeaton


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. 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.

like image 27
Paradox Avatar answered Apr 17 '26 04:04

Paradox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!