Linking custom C++ libraries in XCode 3

Discussion in 'Mac Programming' started by mox123, May 19, 2011.

  1. macrumors 6502

    #1
    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::(
     
  2. macrumors 6502a

    #2
  3. macrumors 6502

    #3
    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...
     
  4. macrumors newbie

    #4
    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,
     
  5. lloyddean, May 19, 2011
    Last edited: May 19, 2011

    macrumors 6502a

    #5
    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>
     
  6. macrumors 6502a

    #6
    Go into project settings and make sure that the header and library paths are included:

    [​IMG]

    Don't tick recursive.

    [​IMG]

    This is: -litpp -lfftw3 -llapack -lblas

    Here is an example you can test:

    Code:
    #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:

    Code:
    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]]
     
  7. macrumors 6502

    #7

    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!!
     
  8. macrumors 6502a

    #8
    I'm using XCode 4. I haven't found a place to put default flags but I'm sure it's possible.
     
  9. macrumors 6502

    #9
    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:
     
  10. macrumors 6502a

Share This Page