gcc compile / link questions

Discussion in 'Python' started by Edward C. Jones, Nov 1, 2003.

  1. I compile and link Python extension modules using the script

    gcc -fPIC -g -I/usr/local/include/python2.3 \
    -Wall -Wstrict-prototypes -c mymodule.c
    g++ -shared mymodule.o -L/usr/local/lib -o mymodule.so

    It works for me but it isn't pretty. Is there a better way to write it?

    Gcc finds all the libraries that need to be linked in. For example,
    "/usr/local/lib/python2.3/site-packages/numarray/libnumarray.so". How
    does gcc do this?

    I created a .so file "utilities.so" that contains some C functions that
    are called in mymodule.c but are not visible from Python. Both
    "utilities.c" and "mymodule.c" use numarray. What changes do I make in
    the script above? Must I use the nasty "libnumarray_UNIQUE_SYMBOL" trick?

    What is a script for creating "utilities.a" using gcc? How do I change
    the script above to include "utilities.a"?
     
    Edward C. Jones, Nov 1, 2003
    #1
    1. Advertising

  2. "Edward C. Jones" <> writes:

    > I compile and link Python extension modules using the script
    >
    > gcc -fPIC -g -I/usr/local/include/python2.3 \
    > -Wall -Wstrict-prototypes -c mymodule.c
    > g++ -shared mymodule.o -L/usr/local/lib -o mymodule.so
    >
    > It works for me but it isn't pretty. Is there a better way to write it?


    Yes, you should write a setup.py using distutils.

    > Gcc finds all the libraries that need to be linked in. For example,
    > "/usr/local/lib/python2.3/site-packages/numarray/libnumarray.so". How
    > does gcc do this?


    I doubt this statement. gcc does not find things in
    /usr/local/lib/python2.3. Why do you think it does?

    > I created a .so file "utilities.so" that contains some C functions
    > that are called in mymodule.c but are not visible from Python. Both
    > "utilities.c" and "mymodule.c" use numarray. What changes do I make in
    > the script above? Must I use the nasty "libnumarray_UNIQUE_SYMBOL"
    > trick?


    You cannot access symbols from different extension modules; each
    module has its own, separate, space of symbols. If you want to invoke
    functions in a different module, you must do so through the Python
    API.

    Some extension modules provide a CObject containing the API; if
    numarray offers such a thing, you should use it.

    Regards,
    Martin
     
    Martin v. =?iso-8859-15?q?L=F6wis?=, Nov 1, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    867
    Kevin Spencer
    May 17, 2005
  2. Replies:
    8
    Views:
    436
  3. Replies:
    5
    Views:
    364
    Nathan Addy
    Sep 17, 2005
  4. Nagaraj
    Replies:
    1
    Views:
    879
    Lionel B
    Mar 1, 2007
  5. fAnSKyer
    Replies:
    2
    Views:
    537
    Alf P. Steinbach
    Jun 7, 2009
Loading...

Share This Page