Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
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.
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
Add this to your .profile:

PATH="/usr/local/bin:/usr/bin:/sw/bin:/usr/local/sbin:/usr/sbin/:/sw/sbin"
C_INCLUDE_PATH="/usr/include:/usr/local/include:/sw/include"
LIBRARY_PATH="/usr/local/lib:/usr/lib:/sw/lib"
LD_LIBRARY_PATH="/usr/local/lib:/usr/lib:/sw/lib"
DYLD_LIBRARY_PATH="/usr/local/lib:/usr/lib:/sw/lib"

export PATH C_INCLUDE_PATH LIBRARY_PATH LD_LIBRARY_PATH DYLD_LIBRARY_PATH

Add any other paths that you need in.
 

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
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!
 

Attachments

  • Picture 1.png
    Picture 1.png
    85.5 KB · Views: 100

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
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!
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
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.
 

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
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.

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)?
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
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?

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.
 

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
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.

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?
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
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?

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.
 

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
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.

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?
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
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.
 

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
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.

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

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
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.
 

Attachments

  • FrameworkMaker.zip
    17.1 KB · Views: 897

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.