PDA

View Full Version : Linking custom C++ libraries in XCode 3




mox123
May 19, 2011, 10:11 AM
So I have begun using XCode as my default C++ writer. I have been trying to link IT++ and Newmat libraries to do vector and matrices computations using C++. Sadly, I can't get XCode to link up when i compile....

#include <itpp/itbase.h>

I have put the folder inside the project folder, but somehow it can't recognize the path. Could someone please please pretty please give me some suggestions? :confused::(



Hansr
May 19, 2011, 10:30 AM
After installing and compiling the libraries you need to include their location in the header search path for the project:

http://research.tannerpages.com/Blog/Good-Samartin-Blog/How-to-install-it---on-Mac-OS-X-10-4-9

mox123
May 19, 2011, 01:46 PM
thank you! I have installed FFTW and ITPP v4.2 in my system. But

#include <itpp/itbase.h>

is still not recognized when I compile from Xcode....what else am i missing? :( :confused:

i apologize for being a noob about Xcode...

dioderm
May 19, 2011, 02:52 PM
So I have begun using XCode as my default C++ writer. I have been trying to link IT++ and Newmat libraries to do vector and matrices computations using C++. Sadly, I can't get XCode to link up when i compile....

#include <itpp/itbase.h>

I have put the folder inside the project folder, but somehow it can't recognize the path. Could someone please please pretty please give me some suggestions? :confused::(

I think what you probably want to use is

#include "itpp/itbase.h"

If you use angle brackets (as you did) the preprocessor looks in the system libraries. If you use quotes, the preprocessor looks in the current directory. Also note that you have a directory name specified there -- it is going to look for a directory named "ittp", and in that directory should be the "itbase.h". You'll need to fix that if it is not the case.

Alternatively you could add the current directory to the $LIB variable (er... XCode does this different I think...) but that is not recommended.

Cheers,

lloyddean
May 19, 2011, 03:27 PM
You haven't specified which version Xcode you're using but I'll assume it's some version of Xcode 4.x and point you at Xcode's "Source Trees" documentation. If you haven't already gone to "Preferences" -> "Documentation" and fetched the most current documentation I'd suggest doing so.

<file:///Library/Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.DeveloperTools.docset/Contents/Resources/Documents/index.html#recipes/xcode_help-source_trees_preferences/About.html#//apple_ref/doc/uid/TP40010512-CH1-SW2>

Hansr
May 19, 2011, 07:44 PM
Go into project settings and make sure that the header and library paths are included:

http://www.hlynsson.com/myndir/ZZ1F69F41F.jpg

Don't tick recursive.

http://www.hlynsson.com/myndir/ZZ5BA455FC.jpg

This is: -litpp -lfftw3 -llapack -lblas

Here is an example you can test:

#include <itpp/itbase.h>

using namespace itpp;
using std::cout;
using std::endl;

int main()
{
vec a, b, c;
mat A, B;

a = linspace(1.1, 2.0, 10);
b = "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0";
c = a + b;

cout << "a = " << a << endl;
cout << "b = " << b << endl;
cout << "c = " << c << endl;

A = "1.0 2.0;3.0 4.0";
B = inv(A);

cout << "A = " << A << endl;
cout << "B = " << B << endl;

return 0;
}

The results should be:

a = [1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2]
b = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1]
c = [1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3]
A = [[1 2]
[3 4]]
B = [[-2 1]
[1.5 -0.5]]

mox123
May 20, 2011, 10:01 PM
Go into project settings and make sure that the header and library paths are included:

Image (http://www.hlynsson.com/myndir/ZZ1F69F41F.jpg)

Don't tick recursive.

Image (http://www.hlynsson.com/myndir/ZZ5BA455FC.jpg)

This is: -litpp -lfftw3 -llapack -lblas

Here is an example you can test:

#include <itpp/itbase.h>

using namespace itpp;
using std::cout;
using std::endl;

int main()
{
vec a, b, c;
mat A, B;

a = linspace(1.1, 2.0, 10);
b = "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0";
c = a + b;

cout << "a = " << a << endl;
cout << "b = " << b << endl;
cout << "c = " << c << endl;

A = "1.0 2.0;3.0 4.0";
B = inv(A);

cout << "A = " << A << endl;
cout << "B = " << B << endl;

return 0;
}

The results should be:

a = [1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2]
b = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1]
c = [1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3]
A = [[1 2]
[3 4]]
B = [[-2 1]
[1.5 -0.5]]


THANK YOU!!!! This does the trick!!! Using command line in the command prompt is definitely way more straightforward.

What version of XCode do you have? yours doesn't look like mine at all in project settings...

Is there any way I can make the linker flags my default setting, as supposed to setting it in every project that makes use of itpp??

thank you SO MUCH again for your help!!

Hansr
May 21, 2011, 10:56 AM
I'm using XCode 4. I haven't found a place to put default flags but I'm sure it's possible.

mox123
May 23, 2011, 07:28 AM
pardon my another noob xcode question: is XCode 4 out already? I have only 3.2, and i thought it had come with snow leopard? :confused:

Hansr
May 23, 2011, 07:44 AM
Xcode 4 came out in March:
http://developer.apple.com/technologies/tools/whats-new.html