Re: Dynamic library linking

2013-02-24 Thread Boyd Collier
I'm just getting started with python, so I'm certainly not qualified to comment 
on this specific problem.  However, perhaps the following page may be useful to 
others getting started with python:

http://wolfpaulus.com/journal/mac/installing_python_osx

The site gives detailed instructions on installing what was, when written, the 
latest version of python (2.7, I believe), which didn't work for me until I 
redid everything, following the steps given including those given by Simon in a 
comment.  

Boyd



On Feb 24, 2013, at 12:09 PM, ecir hana wrote:

> Hello,
> 
> I have a simple program which I can compile but when I tried to link it
> with a dynamic library the linker is not able to find the library, despite
> that it is in the same folder as the program.
> 
> The longer version: I want to embed Python 3.3 interpreter into simple C
> program. I'm on MacOS 10.8, which ships with Python 2.7. I downloaded the
> binary distribution of 3.3 version from python.org, copied the dynamic
> library from the bundle to a folder, along with all the headers. The
> library I copied was a file named "Python" which had a symlink pointing to
> it named "libpython3.3m.dylib". Now that the library is in the folder,  I
> renamed it to "python33" so it wouldn't collide with installed "Python" of
> version 2.7.
> 
> So the folder has these files: "embed.c", "python33" and "include" folder.
> The "embed.c" containts:
> 
>#include 
> 
>int
>main(int argc, char *argv[])
>{
>  Py_Initialize();
>  PyRun_SimpleString("print 'test'\n");
>  Py_Finalize();
>  return 0;
>}
> 
> and running "file python33" says:
> 
>python33 (for architecture i386): Mach-O dynamically linked shared
> library i386
>python33 (for architecture x86_64): Mach-O 64-bit dynamically linked
> shared library x86_64
> 
> The problem I have is that when try to run:
> 
>"gcc embed.c -I./include -L. -lpython33"
> 
> if breaks with:
> 
>ld: library not found for -lpython33
> 
> Please, does anyone know why?
> 
> I guess this is not exactly Cocoa-related question but I tried to ask about
> this at various places and I have not found a solution, yet.
> 
> I have various theories about why this happens, I would be thankful if
> someone could confirm/reject these:
> 
> - I cannot just copy out a dynamic library out of a bundle, I have to
> install the whole Python 3.3 and after it is properly installed at
> particular locations, then I can link with it.
> 
> - I'm missing some linker flags. I tried "DYLD_LIBRARY_PATH="."" but it
> didn't help.
> 
> - The Python 3.3 library was compiled with different compiler that what I
> use to compile my program with.
> 
> PS: it compiles with:
> 
>"gcc embed.c -I./include python33"
> 
> but when I tun "./a.out" it breaks with:
> 
>dyld: Library not loaded:
> /Library/Frameworks/Python.framework/Versions/3.3/Python
>Referenced from: /Users/ecir/Desktop/embed/./a.out
>Reason: image not found
>Trace/BPT trap: 5
> 
> I would really appreciate any hint on how to solve this, thank you in
> advace!
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/bcollier2%40cox.net
> 
> This email sent to bcolli...@cox.net


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Dynamic library linking

2013-02-24 Thread ecir hana
Marco S Hyman, Stephen J. Butler,

thanks a lot! Indeed, stupid me, I was missing "-L.". I used to use it (as
I copy-pasted above) but somehow when hitting up arrow in terminal I must
have accidentally deleted it. Now it links! So to recap, properly naming
the library ("libpython33.so") and compiling with:

gcc embed.c -I./include -L. -lpython33

works! Thank you so much people!

The problem is, as Stephen points out, the executable doesn't run:

Reason: image not found
Trace/BPT trap: 5

I will read the links about frameworks now...


On Sun, Feb 24, 2013 at 10:20 PM, Stephen J. Butler <
stephen.but...@gmail.com> wrote:

> This is an advanced topic which touches on a lot of OS X details. The
> short of it is, even if you solve your linking problems your Python 3.3
> library won't work.
>
> What you need to is include the entire Python 3.3 framework in your
> Application bundle. Once you've figured out how to do that, linking against
> it is as simple as telling Xcode to link the framework. Here are two links
> some Googling brought up:
>
> Here's the official docs:
>
>
> https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html
>
> Look under "Embedding a Private Framework in Your Application Bundle" and
> start following links. This StackOverflow question touches on the subject:
>
>
> http://stackoverflow.com/questions/1621451/bundle-framework-with-application-in-xcode
>
>
>
> On Sun, Feb 24, 2013 at 2:09 PM, ecir hana  wrote:
>
>> Hello,
>>
>> I have a simple program which I can compile but when I tried to link it
>> with a dynamic library the linker is not able to find the library, despite
>> that it is in the same folder as the program.
>>
>> The longer version: I want to embed Python 3.3 interpreter into simple C
>> program. I'm on MacOS 10.8, which ships with Python 2.7. I downloaded the
>> binary distribution of 3.3 version from python.org, copied the dynamic
>> library from the bundle to a folder, along with all the headers. The
>> library I copied was a file named "Python" which had a symlink pointing to
>> it named "libpython3.3m.dylib". Now that the library is in the folder,  I
>> renamed it to "python33" so it wouldn't collide with installed "Python" of
>> version 2.7.
>>
>> So the folder has these files: "embed.c", "python33" and "include" folder.
>> The "embed.c" containts:
>>
>> #include 
>>
>> int
>> main(int argc, char *argv[])
>> {
>>   Py_Initialize();
>>   PyRun_SimpleString("print 'test'\n");
>>   Py_Finalize();
>>   return 0;
>> }
>>
>> and running "file python33" says:
>>
>> python33 (for architecture i386): Mach-O dynamically linked shared
>> library i386
>> python33 (for architecture x86_64): Mach-O 64-bit dynamically linked
>> shared library x86_64
>>
>> The problem I have is that when try to run:
>>
>> "gcc embed.c -I./include -L. -lpython33"
>>
>> if breaks with:
>>
>> ld: library not found for -lpython33
>>
>> Please, does anyone know why?
>>
>> I guess this is not exactly Cocoa-related question but I tried to ask
>> about
>> this at various places and I have not found a solution, yet.
>>
>> I have various theories about why this happens, I would be thankful if
>> someone could confirm/reject these:
>>
>> - I cannot just copy out a dynamic library out of a bundle, I have to
>> install the whole Python 3.3 and after it is properly installed at
>> particular locations, then I can link with it.
>>
>> - I'm missing some linker flags. I tried "DYLD_LIBRARY_PATH="."" but it
>> didn't help.
>>
>> - The Python 3.3 library was compiled with different compiler that what I
>> use to compile my program with.
>>
>> PS: it compiles with:
>>
>> "gcc embed.c -I./include python33"
>>
>> but when I tun "./a.out" it breaks with:
>>
>> dyld: Library not loaded:
>> /Library/Frameworks/Python.framework/Versions/3.3/Python
>> Referenced from: /Users/ecir/Desktop/embed/./a.out
>> Reason: image not found
>> Trace/BPT trap: 5
>>
>> I would really appreciate any hint on how to solve this, thank you in
>> advace!
>> ___
>>
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>> https://lists.apple.com/mailman/options/cocoa-dev/stephen.butler%40gmail.com
>>
>> This email sent to stephen.but...@gmail.com
>>
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Dynamic library linking

2013-02-24 Thread Stephen J. Butler
This is an advanced topic which touches on a lot of OS X details. The short
of it is, even if you solve your linking problems your Python 3.3 library
won't work.

What you need to is include the entire Python 3.3 framework in your
Application bundle. Once you've figured out how to do that, linking against
it is as simple as telling Xcode to link the framework. Here are two links
some Googling brought up:

Here's the official docs:

https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html

Look under "Embedding a Private Framework in Your Application Bundle" and
start following links. This StackOverflow question touches on the subject:

http://stackoverflow.com/questions/1621451/bundle-framework-with-application-in-xcode



On Sun, Feb 24, 2013 at 2:09 PM, ecir hana  wrote:

> Hello,
>
> I have a simple program which I can compile but when I tried to link it
> with a dynamic library the linker is not able to find the library, despite
> that it is in the same folder as the program.
>
> The longer version: I want to embed Python 3.3 interpreter into simple C
> program. I'm on MacOS 10.8, which ships with Python 2.7. I downloaded the
> binary distribution of 3.3 version from python.org, copied the dynamic
> library from the bundle to a folder, along with all the headers. The
> library I copied was a file named "Python" which had a symlink pointing to
> it named "libpython3.3m.dylib". Now that the library is in the folder,  I
> renamed it to "python33" so it wouldn't collide with installed "Python" of
> version 2.7.
>
> So the folder has these files: "embed.c", "python33" and "include" folder.
> The "embed.c" containts:
>
> #include 
>
> int
> main(int argc, char *argv[])
> {
>   Py_Initialize();
>   PyRun_SimpleString("print 'test'\n");
>   Py_Finalize();
>   return 0;
> }
>
> and running "file python33" says:
>
> python33 (for architecture i386): Mach-O dynamically linked shared
> library i386
> python33 (for architecture x86_64): Mach-O 64-bit dynamically linked
> shared library x86_64
>
> The problem I have is that when try to run:
>
> "gcc embed.c -I./include -L. -lpython33"
>
> if breaks with:
>
> ld: library not found for -lpython33
>
> Please, does anyone know why?
>
> I guess this is not exactly Cocoa-related question but I tried to ask about
> this at various places and I have not found a solution, yet.
>
> I have various theories about why this happens, I would be thankful if
> someone could confirm/reject these:
>
> - I cannot just copy out a dynamic library out of a bundle, I have to
> install the whole Python 3.3 and after it is properly installed at
> particular locations, then I can link with it.
>
> - I'm missing some linker flags. I tried "DYLD_LIBRARY_PATH="."" but it
> didn't help.
>
> - The Python 3.3 library was compiled with different compiler that what I
> use to compile my program with.
>
> PS: it compiles with:
>
> "gcc embed.c -I./include python33"
>
> but when I tun "./a.out" it breaks with:
>
> dyld: Library not loaded:
> /Library/Frameworks/Python.framework/Versions/3.3/Python
> Referenced from: /Users/ecir/Desktop/embed/./a.out
> Reason: image not found
> Trace/BPT trap: 5
>
> I would really appreciate any hint on how to solve this, thank you in
> advace!
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> https://lists.apple.com/mailman/options/cocoa-dev/stephen.butler%40gmail.com
>
> This email sent to stephen.but...@gmail.com
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Dynamic library linking

2013-02-24 Thread ecir hana
Ken Thomases, Ben Kennedy,

thanks for the replies!

Yes, I tried "libpython33.so", "libpython33.dylib", "python33.dylib", ...

But I still get that error, even if the file is "ls -al":

-r-xr-xr-x@   1 ecir  staff  5503912 29 sep 10:27 libpython33.so

That "-v" switch is a good advice but I cannot really make any sense of
this http://pastebin.com/ugWxEWw8


On Sun, Feb 24, 2013 at 9:51 PM, Ken Thomases  wrote:

> On Feb 24, 2013, at 2:09 PM, ecir hana wrote:
>
> > and running "file python33" says:
> >
> >python33 (for architecture i386): Mach-O dynamically linked shared
> > library i386
> >python33 (for architecture x86_64): Mach-O 64-bit dynamically linked
> > shared library x86_64
> >
> > The problem I have is that when try to run:
> >
> >"gcc embed.c -I./include -L. -lpython33"
> >
> > if breaks with:
> >
> >ld: library not found for -lpython33
> >
> > Please, does anyone know why?
>
> The -l option expects a file with the prefix "lib" and a library suffix.
>  So, -lpython33 requires that the file be named libpython33.
> (where something might be dylib or a or possibly a couple of other things).
>
> When you have issues like this, you might try passing -v for verbose
> output.  It would probably tell you precisely which file names it tried.
>
> Regards,
> Ken
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Dynamic library linking

2013-02-24 Thread Ken Thomases
On Feb 24, 2013, at 2:09 PM, ecir hana wrote:

> and running "file python33" says:
> 
>python33 (for architecture i386): Mach-O dynamically linked shared
> library i386
>python33 (for architecture x86_64): Mach-O 64-bit dynamically linked
> shared library x86_64
> 
> The problem I have is that when try to run:
> 
>"gcc embed.c -I./include -L. -lpython33"
> 
> if breaks with:
> 
>ld: library not found for -lpython33
> 
> Please, does anyone know why?

The -l option expects a file with the prefix "lib" and a library suffix.  So, 
-lpython33 requires that the file be named libpython33. (where 
something might be dylib or a or possibly a couple of other things).

When you have issues like this, you might try passing -v for verbose output.  
It would probably tell you precisely which file names it tried.

Regards,
Ken


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com