Newbie Questions about Fink

Discussion in 'Mac Programming' started by Soulstorm, Nov 16, 2008.

  1. Soulstorm macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #1
    I have problems installing some external libraries I want, so I decided to download fink and try to install them from there. I installed Fink, and I opened FinkCommander, and tried to install some libraries, like the "pcre" library.

    However, Fink installs them into a folder named "sw" into my startup disk. How can I use the libraries from there? I open Xcode, I make a new C++ command line project and I type "#include <pcre.h>" and it can't find that directory.

    How can I make my Xcode look into the directory where Fink stores the downloaded files? Does it have something to do with my .profile in my home folder?

    In case you need the contents of that file, here they are.

    Code:
    ##
    # DELUXE-USR-LOCAL-BIN-INSERT
    # (do not remove this comment)
    ##
    echo $PATH | grep -q -s "/usr/local/bin"
    if [ $? -eq 1 ] ; then
        PATH=$PATH:/usr/local/bin
        export PATH
    fi
    
    test -r /sw/bin/init.sh && . /sw/bin/init.sh
    
    Please help! I am trying to install pcre, because I need it!
    Thanks in advance.
     
  2. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #2
    Add this to your .profile:

    Add any other paths that you need in.
     
  3. Soulstorm thread starter macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #3
    Nice idea, but it still doesn't work.. I am attaching the files so that you may verify what I am saying...

    and here is my code:

    Code:
    #include <iostream>
    #include <vector>
    #include <string>
    #include "tgaloaders.h"
    #include <pcre.h>
    using namespace std;
    
    int main(){
    }
    It complains it can't find the "pcre.h" header. Why/? Since I have it inside the appropriate folder and I have se my environment variables correctly!
     

    Attached Files:

  4. Soulstorm thread starter macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #4
    Cromulent, have you done with Fink what I want to do? If yes, what steps did you follow exactly?

    I also tried installing Fink and Xcode in a newly installed OS X Leopard. Same thing happens. Help!
     
  5. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #5
    Are you including the dylib in your project as well? Also you need to configure the header search path in your project settings as well (for both debug and release). Just set it too /sw/include and click the recursive button.
     
  6. Soulstorm thread starter macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #6
    Now I am getting somewhere... In my Xcode project, I added the search path for the headers like you said, and It compiles, ok, BUT I have the feeling that it just included the header and not the dylib. How do I include the dylibs? Using the same way as any other header? Like "#include <iostream>" in my main.cpp file, or is there another way (drag and drop, for example)?
     
  7. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #7
    Project menu -> Edit Active Target "project name"

    Then in the window that opens click the general tab. Then in the bottom where it says linked libraries click the + button and add the library from the list. Make sure it says required next to it.
     
  8. Soulstorm thread starter macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #8
    Same thing happens if I drag the dylib and drop it onto the project window... I did that. However, my question is What should write into my simple main.cpp file. Should I write #include directives? Should I just call the functions from a dylib without writing #include for anything?
     
  9. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #9
    Well you need include the relevant header. From the looks of your code above you already have it. From now on you need to read the API documentation.
     
  10. Soulstorm thread starter macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #10
    Your help was invaluable. Thanks a lot. Now, a last favor would be to point me into some references. Apple sure doesn't explin a lot about dynamic LIbraries... Do you know of any good book where I can learn about creating/using static and dynamic libraries with XCode? And perhaps a little bit of learnign Unix commands?
     
  11. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #11
    Static libs get packaged into the resulting binary, dylib are like bare-metal frameworks e.g. they remain discrete files. Typ. if you link against a dylib then your deployed app will look for the same dylib on another system. You can see what libs are linked in a binary using the command line tool 'otool' like this:

    Code:
    otool -L <path to binary file>
    That produces this:

    Code:
    	@executable_path/../Frameworks/libUPnPDyld.framework/Versions/A/libUPnPDyld (compatibility version 1.0.0, current version 1.0.0)
    	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 476.0.0)
    	/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
    The first line is an app framework, the second is a system framework, and the last is a dylib.

    I grabbed a python script from the Adium SVN repository that converts a dylib into a framework called frameworktize.py. So now I can get an open source project, make a dylib and convert that to a framework for use in Mac OS X Cocoa apps.
     
  12. Soulstorm thread starter macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #12
    That's exactly what I was lookinf for. But where is it exactly? I am searching in there svn but i am unable to find it...
     
  13. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #13
    Script

    I uploaded Framework making script here. There's actually four parts, but you just type this in the Terminal to run it (after installing 'rtool'):

    Code:
    python /Users/neonitride/Downloads/frameworkize.py /Users/neonitride/Sources/UPnPDyld/build/Release/libUPnPDyld.dylib  ~/Sources
    Also to get the headers in the Framework that is created you need to do this:

    In the folder where the compiled dylib file is located make a folder path like this "include/<name of dylib>/<all public header files>"

    Like this: UPnPDyld/build/Release/include/libUPnPDyld/<header files>

    If you do this the python script will pull the header files and copy them to the framework when you build it.
     

    Attached Files:

  14. Soulstorm thread starter macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #14
    Thanks a lot! However, I installed rtool and ran the commands you see in the source below. I received strange errors about UNIX commands not found in the terminal:

    Code:
    christos-sotirious-imac:~ soulstorm$ python /Users/soulstorm/Downloads/FrameworkMaker/frameworkize.py /sw/lib/libpng12.0.dylib /Users/soulstorm/Downloads/FrameworkMaker/sources 
    /usr/local/bin/rtool: line 377: rm: command not found
    /usr/local/bin/rtool: line 380: mkdir: command not found
    /usr/local/bin/rtool: line 158: mkdir: command not found
    /usr/local/bin/rtool: line 148: /Users/soulstorm/Downloads/FrameworkMaker/sources/libpng.subproj/libpng.framework/Versions/12.0/Resources/English.lproj/InfoPlist.strings: No such file or directory
    /usr/local/bin/rtool: line 148: /Users/soulstorm/Downloads/FrameworkMaker/sources/libpng.subproj/libpng.framework/Versions/12.0/Resources/English.lproj/InfoPlist.strings: No such file or directory
    /usr/local/bin/rtool: line 148: /Users/soulstorm/Downloads/FrameworkMaker/sources/libpng.subproj/libpng.framework/Versions/12.0/Resources/English.lproj/InfoPlist.strings: No such file or directory
    /usr/local/bin/rtool: line 163: chmod: command not found
    /usr/local/bin/rtool: line 386: mkdir: command not found
    /usr/local/bin/rtool: line 388: cp: command not found
    /usr/local/bin/rtool: line 389: chmod: command not found
    /usr/local/bin/rtool: line 425: mkdir: command not found
    /usr/local/bin/rtool: line 435: cp: command not found
    find: /Users/soulstorm/Downloads/FrameworkMaker/sources/libpng.subproj/libpng.framework/Versions/12.0/Headers: No such file or directory
    /usr/local/bin/rtool: line 451: chmod: command not found
    find: /Users/soulstorm/Downloads/FrameworkMaker/sources/libpng.subproj/libpng.framework/Versions/12.0/Headers: No such file or directory
    /usr/local/bin/rtool: line 452: chmod: command not found
    /usr/local/bin/rtool: line 476: ls: command not found
    /usr/local/bin/rtool: line 484: ln: command not found
    Something went wrong. rtool failed for  /sw/lib/libpng12.0.dylib  with status  127
    christos-sotirious-imac:~ soulstorm$ 
    I tested the commands the script couldn't find, and all function correctly... Perhaps I missed a step. Should I create the directory structure before running the script? Any ideas?
     

Share This Page