Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6146911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:01:40+00:00 2026-05-23T19:01:40+00:00

I wan’t want to create a cross-plattform programm that embedds the python interpreter, and

  • 0

I wan’t want to create a cross-plattform programm that embedds the python interpreter, and compile it with MinGW. But the Python Binary distribution provides no libraries for MinGW to link with (only python32.lib for Visual C++), and the Python Source package provides no support for compiling with MinGW.

I tried linking to python32.lib in Mingw with -lpython32 but it still generates errors like:

main.cpp: undefined reference to `_imp__Py_Initialize'
main.cpp: undefined reference to `_imp__Py_Finalize'

How do I link Python in MinGW? I really don’t want to switch to using Visual C++.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:01:40+00:00Added an answer on May 23, 2026 at 7:01 pm

    With nm and dlltool from binutils, you should be able to rebuild the library for gcc:

    echo EXPORTS > python32.def
    nm python32.lib | grep " T _" | sed "s/.* T _//" >> python32.def
    dlltool --input-def python32.def --dllname python32 --output-lib libpython32.a
    

    python_test.c:

    #include "Python.h"
    
    int main(int argc, char *argv[]) {
        Py_Initialize();
        PyRun_SimpleString("from time import time,ctime\n"
                           "print('Today is',ctime(time())\n)");
        Py_Finalize();
        return 0;
    }
    

    Compile:

    gcc -Wall -IC:\Python32\include -LC:\Python32\libs -o python_test.exe python_test.c -lpython32
    

    Test:

    C:\python_test.exe
    Today is Mon Jul 18 08:50:53 2011
    

    Edit: If you’d prefer to skip building this yourself on x64, you can download it for several versions from Christoph Gohlke’s Unofficial Windows Binaries for Python Extension Packages.

    Edit: Here’s a Python version based on the existing function that’s distributed in Tools/msi/msi.py:

    import subprocess
    import warnings
    import re
    
    NM = 'x86_64-w64-mingw32-nm'
    DLLTOOL = 'x86_64-w64-mingw32-dlltool'
    EXPORT_PATTERN = r'^[_]{1,2}imp_(?P<export>.*) in python\d+\.dll'
    
    def build_libpython(ver, nm=NM, dlltool=DLLTOOL,
                        export_pattern=EXPORT_PATTERN):
        pylib = 'python%s.lib' % ver
        pydef = 'python%s.def' % ver
        pydll = 'python%s.dll' % ver
        libpy = 'libpython%s.a' % ver
        warning = '%s failed - ' + '%s not built' % libpy
        match_export = re.compile(export_pattern).match
        cmd_nm = [nm, '-Cs', pylib]
        cmd_dlltool = [dlltool, 
                       '--dllname', pydll, 
                       '--def', pydef,
                       '--output-lib', libpy]
        with open(pydef, 'w') as f:
            f.write('LIBRARY %s\nEXPORTS\n' % pydll)
            p_nm = subprocess.Popen(cmd_nm, 
                                    stdout=subprocess.PIPE,
                                    universal_newlines=True)
            for line in sorted(p_nm.stdout):
                m = match_export(line)
                if m:
                    f.write(m.group('export') + '\n')
            if p_nm.wait() != 0:
                warnings.warn(warning % nm)
                return False
        if subprocess.call(cmd_dlltool) != 0:
            warnings.warn(warning % dlltool)
            return False
        return True
    

    For example:

    import os
    for n in (27, 33, 35):
        pylib = 'python%s.lib' % n
        if os.path.exists(pylib):
            build_libpython(n)
            pydef = 'python%s.def' % n            
            lc_def = sum(1 for line in open(pydef))
            libpy = 'libpython%s.a' % n
            lc_lib = sum(1 for line in os.popen('ar -t %s' % libpy))
            assert lc_def == lc_lib
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I want to create a 64bit application in c# and I wan't to
i wan to create a program that can get the application name i can
How wan i display text in an OpenGL program? I'm using MinGW, but the
I wan't to create an applet that includes the Java compiler and is able
I want to use ms office communicator client apis, and i wan to use
I wan't to connect to remote web page (that has login form) with HttpWebRequest.
I wan to learn 1). How to call assembly code so that I can
I wan't to use some C source in my Objective-c proj but the source
I wan't to have a function that turns spell check on then go's to
hi m trying fill the combo box from cities database but i wan the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.