Problem with building extension in Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vedrandekovic@v-programs.com

    #1

    Problem with building extension in Python

    Hi,

    I have already install Microsoft visual studio .NET 2003 and MinGw,
    when I try to build a extension:

    python my_extension_se tup.py build ( or install ) , I get an error:

    LINK : fatal error LNK1141: failure during build of exports file
    error: command '"C:\Program Files\Microsoft Visual Studio .NET
    2003\Vc7\bin\li nk.exe"' failed with exit status 1141.What shoud I
    do???

    If you now anything useful,
    please contact me!!






    Thanks!!!!!!!!! !

  • Stefan Behnel

    #2
    Re: Problem with building extension in Python

    vedrandekovic@v-programs.com wrote:
    I have already install Microsoft visual studio .NET 2003 and MinGw,
    when I try to build a extension:
    >
    python my_extension_se tup.py build ( or install ) , I get an error:
    >
    LINK : fatal error LNK1141: failure during build of exports file
    error: command '"C:\Program Files\Microsoft Visual Studio .NET
    2003\Vc7\bin\li nk.exe"' failed with exit status 1141.
    >
    What shoud I do???
    Tell us what the actual error message is? What you provide here is only the
    last line, the real error is most likely before that. Please provide a bit
    more of the output, anything that might be helpful to understand the problem.

    Stefan

    Comment

    • Gabriel Genellina

      #3
      Re: Problem with building extension in Python

      En Thu, 05 Jul 2007 05:08:58 -0300, <vedrandekovic@ v-programs.com>
      escribió:
      I have already install Microsoft visual studio .NET 2003 and MinGw,
      when I try to build a extension:
      Is this for Python 2.4? I think you can't compile Python 2.5 with VS2003.
      python my_extension_se tup.py build ( or install ) , I get an error:
      >
      LINK : fatal error LNK1141: failure during build of exports file
      error: command '"C:\Program Files\Microsoft Visual Studio .NET
      2003\Vc7\bin\li nk.exe"' failed with exit status 1141.What shoud I
      do???
      Almost surely you got a previous error, making link to fail. Try to
      correct *that* error.

      --
      Gabriel Genellina

      Comment

      • cornpicker@gmail.com

        #4
        Re: Problem with building extension in Python

        On Jul 5, 4:33 am, "Gabriel Genellina" <gagsl-...@yahoo.com.a rwrote:
        En Thu, 05 Jul 2007 05:08:58 -0300, <vedrandeko...@ v-programs.com>
        escribió:
        >
        I have already install Microsoft visual studio .NET 2003 and MinGw,
        when I try to build a extension:
        >
        Is this for Python 2.4? I think you can't compile Python 2.5 with VS2003.
        >
        python my_extension_se tup.py build ( or install ) , I get an error:
        >
        LINK : fatal error LNK1141: failure during build of exports file
        error: command '"C:\Program Files\Microsoft Visual Studio .NET
        2003\Vc7\bin\li nk.exe"' failed with exit status 1141.What shoud I
        do???
        >
        Almost surely you got a previous error, making link to fail. Try to
        correct *that* error.
        >
        --
        Gabriel Genellina
        Microsoft Visual Studio .NET 2003 Version 7.1 is the correct
        version to build extensions for Python 2.5. There is also a Microsoft
        Visual Studio .NET 2003 Version 7.0 as well, which is not acceptable
        for building extensions. The first release (version 7.0) was purchased
        by many, and is relatively easy to find. The following release
        (version 7.1) was a minor revision and is very hard to find, but it is
        what's necessary for building Python extensions. I hope future Python
        releases are built using a more standard compiler.

        I'm posting in this thread because I am running into the same
        problem as the original poster, linker error 1141. Here's a summary of
        what I've gotten to work properly so far:

        Python 2.5, Pyrex, and Microsoft Visual Studio 2003 .NET (version 7.1)
        are successfully installed
        I have successfully built Pyrex extensions using Distutils
        I have successfully imported and ran Pyrex extensions in my Python
        code

        The problems occur when I try to include C libraries in my Pyrex
        code. Specifically, I need some trig functions found in C's math.h
        header files. My .pyx file is as follows:



        #
        # Use C math functions
        #

        def cFunctionTester (float theta):

        import sys

        # Import the native C functions we need
        cdef extern from "math.h":
        double cos(double theta)
        double sin(double theta)

        result[0] = cos(theta)
        result[1] = sin(theta)

        return 5



        I try to build the extension by running my setup.py file from the
        command prompt. My setup.py file is presented below:



        from distutils.core import setup
        from distutils.exten sion import Extension
        from Pyrex.Distutils import build_ext
        setup(
        name = "PyrexGuide ",
        ext_modules=[
        Extension("cTes t", ["cTest.pyx"], libraries = [])
        ],
        cmdclass = {'build_ext': build_ext}
        )



        I run this code through the command prompt by entering "setup.py
        install" The following error appears:



        C:\Python25\Lib \site-packages\Pyrex\ Distutils>setup .py install
        running install
        running build
        running build_ext
        building 'cTest' extension
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\cl .exe /c /
        nologo /Ox
        /MD /W3 /GX /DNDEBUG -IC:\Python25\in clude -IC:\Python25\PC /
        TccTest.c /Fobuild
        \temp.win32-2.5\Release\cTe st.obj
        cTest.c
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\li nk.exe /
        DLL /nologo
        /INCREMENTAL:NO /LIBPATH:C:\Pyth on25\libs /LIBPATH:C:
        \Python25\PCBui ld /EXPORT:
        initcTest build\temp.win3 2-2.5\Release\cTe st.obj /OUT:build
        \lib.win32-2.5\cTest.
        pyd /IMPLIB:build\te mp.win32-2.5\Release\cTe st.lib
        LINK : error LNK2001: unresolved external symbol initcTest
        build\temp.win3 2-2.5\Release\cTe st.lib : fatal error LNK1120: 1
        unresolved exter
        nals
        LINK : fatal error LNK1141: failure during build of exports file
        error: command '"c:\Program Files\Microsoft Visual Studio .NET
        2003\Vc7\bin\li nk
        ..exe"' failed with exit status 1141

        C:\Python25\Lib \site-packages\Pyrex\ Distutils>



        I do not know what the problem is -- perhaps the linker cannot locate
        math.h? I've tried copying the math.h file to a whole bunch of other
        directories, but there's still no luck. Any help anyone can provide
        would be greatly appreciated.

        Joe Stoffa
        CornPicker@gmai l.com

        Comment

        • cornpicker@gmail.com

          #5
          Re: Problem with building extension in Python

          I solved my problem.

          I had the math.h import step in the wrong location. The import step
          needed to be outside of the function -- I'm so embarrassed.

          Code: [Download]

          1.
          2. #
          3. # Use C math functions
          4. #
          5.
          6. # Import the native C functions we need
          7. cdef extern from "math.h":
          8. double cos(double theta)
          9. double sin(double theta)
          10.
          11.
          12. def cTest(double theta):
          13.
          14. cdef double result[2]
          15.
          16. import sys
          17.
          18. result[0] = cos(theta)
          19. result[1] = sin(theta)
          20.
          21. pyResult = (result[0], result[1])
          22.
          23. return pyResult
          24.
          25.



          Now it works

          If I type the following into the python shell

          import cTest
          cTest.cTest(.77 5)

          The function returns

          (0.714421034055 93138, 0.6997160753466 0352)


          Comment

          Working...