Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot find -lpythonX.X when building Python on FreeBSD with --enable-shared #48616

Closed
akitada mannequin opened this issue Nov 20, 2008 · 19 comments
Closed

cannot find -lpythonX.X when building Python on FreeBSD with --enable-shared #48616

akitada mannequin opened this issue Nov 20, 2008 · 19 comments
Assignees
Labels
build The build process and cross-build stdlib Python modules in the Lib dir

Comments

@akitada
Copy link
Mannequin

akitada mannequin commented Nov 20, 2008

BPO 4366
Nosy @loewis, @pitrou, @tiran, @tarekziade, @merwok, @akitada, @koobs
Files
  • 4366.diff
  • python-issue4366.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/merwok'
    closed_at = <Date 2013-09-28.23:55:36.598>
    created_at = <Date 2008-11-20.17:26:58.678>
    labels = ['build', 'library']
    title = 'cannot find -lpythonX.X when building Python on FreeBSD with --enable-shared'
    updated_at = <Date 2013-09-28.23:55:36.597>
    user = 'https://github.com/akitada'

    bugs.python.org fields:

    activity = <Date 2013-09-28.23:55:36.597>
    actor = 'pitrou'
    assignee = 'eric.araujo'
    closed = True
    closed_date = <Date 2013-09-28.23:55:36.598>
    closer = 'pitrou'
    components = ['Build', 'Distutils', 'Library (Lib)']
    creation = <Date 2008-11-20.17:26:58.678>
    creator = 'akitada'
    dependencies = []
    files = ['15799', '31843']
    hgrepos = []
    issue_num = 4366
    keywords = ['patch']
    message_count = 19.0
    messages = ['76117', '76118', '76122', '76127', '76361', '76364', '76448', '76458', '76480', '97465', '97466', '97477', '198013', '198017', '198020', '198277', '198340', '198557', '198558']
    nosy_count = 10.0
    nosy_names = ['loewis', 'nbastin', 'pitrou', 'christian.heimes', 'tarek', 'eric.araujo', 'Arfrever', 'akitada', 'python-dev', 'koobs']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'compile error'
    url = 'https://bugs.python.org/issue4366'
    versions = ['Python 2.7', 'Python 3.3', 'Python 3.4']

    @akitada
    Copy link
    Mannequin Author

    akitada mannequin commented Nov 20, 2008

    I get a number of "cannot find -lpython2.5" error when building Python
    2.5.2 on FreeBSD 2.5.2 with gcc 2.95.4.
    This problem is only occured when I build it with "--enable-shared"
    configure option.

    This is how you can reproduce this problem.

    cd Python-2.5.2
    configure --enable-shared
    make

    and you will get

    gcc -shared
    build/temp.freebsd-4.11-RELEASE-i386-2.5/usr/home/build/dev/Python-2.5.2/Modules/struct.o
    -L/usr/local/lib -lpython2.5 -o build/lib.freebsd-4.11-RELEASE-i386-2.5/

    struct.so
    /usr/libexec/elf/ld: cannot find -lpython2.5
    ...
    /home/build/dev/Python-2.5.2/Modules/_ctypes/libffi/src/x86/sysv.o
    -L/usr/local/lib -lpython2.5 -o
    build/lib.freebsd-4.11-RELEASE-i386-2.5/_ctypes.so
    /usr/libexec/elf/ld: cannot find -lpython2.5
    ...
    gcc -shared
    build/temp.freebsd-4.11-RELEASE-i386-2.5/usr/home/build/dev/Python-2.5.2/Modules/_ctypes/_ctypes_test.o
    -L/usr/local/lib -lpython2.5 -o build/lib.freebsd-4.11-RELEA
    SE-i386-2.5/_ctypes_test.so
    /usr/libexec/elf/ld: cannot find -lpython2.5
    ...
    gcc -shared
    build/temp.freebsd-4.11-RELEASE-i386-2.5/usr/home/build/dev/Python-2.5.2/Modules/_weakref.o
    -L/usr/local/lib -lpython2.5 -o build/lib.freebsd-4.11-RELEASE-i386-2.5/
    _weakref.so
    /usr/libexec/elf/ld: cannot find -lpython2.5
    ...
    gcc -shared
    build/temp.freebsd-4.11-RELEASE-i386-2.5/usr/home/build/dev/Python-2.5.2/Modules/arraymodule.o
    -L/usr/local/lib -lpython2.5 -o build/lib.freebsd-4.11-RELEASE-i386-2
    .5/array.so
    /usr/libexec/elf/ld: cannot find -lpython2.5
    ......

    You can workaround this by running ./configure LDFLAGS="-L."
    --enable-shared.

    @akitada akitada mannequin added build The build process and cross-build labels Nov 20, 2008
    @tiran
    Copy link
    Member

    tiran commented Nov 20, 2008

    Please try this patch with a clean source tree. It adds the current
    directory to the library search path.

    Index: setup.py
    ===================================================================

    --- setup.py    (revision 67295)
    +++ setup.py    (working copy)
    @@ -245,6 +245,7 @@
         def detect_modules(self):
             # Ensure that /usr/local is always used
             add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
    +        add_dir_to_list(self.compiler.library_dirs, '.')
             add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
         # Add paths specified in the environment variables LDFLAGS and
    

    @akitada
    Copy link
    Mannequin Author

    akitada mannequin commented Nov 20, 2008

    Christian's patch fixed this problem!
    (tested on 4.11-RELEASE)

    I'm not sure why the other platforms don't suffer this problem.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Nov 20, 2008

    Since r53691, and bpo-1600860, "." is added to library_dirs on Linux
    and GNU systems. This probably should be extended to FreeBSD, and other
    systems.

    The critical point to notice is that the -L option is not only while
    building Python itself, but also for extension modules (assuming Python
    is installed into a non-standard location).

    Now, the question is how to extend this approach to FreeBSD. For 2.5 and
    2.6, I think it is safest to explicitly add freebsd to the list of
    systems tested for.

    For the trunk, and probably 3.0, I would try to add the library whenever
    Py_ENABLE_SHARED is defined, and os.name is posix.

    @akitada
    Copy link
    Mannequin Author

    akitada mannequin commented Nov 24, 2008

    Changing the title because this is not 2.5.x specific.

    @akitada akitada mannequin changed the title cannot find -lpython2.5 when buinding Python 2.5.2 on FreeBSD 4.11 cannot find -lpython2.X when buinding Python on FreeBSD 4.11 Nov 24, 2008
    @akitada
    Copy link
    Mannequin Author

    akitada mannequin commented Nov 24, 2008

    Changing the title again because this problem is not FreeBSD 4 specific.
    Build on recent FreeBSD also has the same problem.
    (I tested this on 6.3, too)

    @akitada akitada mannequin changed the title cannot find -lpython2.X when buinding Python on FreeBSD 4.11 cannot find -lpythonX.X when buinding Python on FreeBSD Nov 24, 2008
    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Nov 26, 2008

    2.5.3 is out of scope for this issue (and thus, the whole of 2.5). There
    is no workable patch, yet, and 2.5.3 is just two weeks ahead.

    @akitada
    Copy link
    Mannequin Author

    akitada mannequin commented Nov 26, 2008

    Martin,
    Two questions:

    1. Isn't Christian's patch enough for this?
    2. How about Python 3.0 and 2.6.1? Are they also out of scope for this?

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Nov 26, 2008

    1. Isn't Christian's patch enough for this?

    No. It should be dealt with in the same way as on Linux (or the Linux
    way should be changed).

    1. How about Python 3.0 and 2.6.1? Are they also out of scope for this?

    Not yet, no. However, they are soon to be released, so chances are low
    that a patch arrives in time.

    @nbastin
    Copy link
    Mannequin

    nbastin mannequin commented Jan 9, 2010

    A more appropriate patch should be (for 2.7 trunk - I'm grabbing a checkout of 3.2 trunk now):

    Index: build_ext.py
    ===================================================================

    --- build_ext.py	(revision 77388)
    +++ build_ext.py	(working copy)
    @@ -280,7 +280,7 @@
             # Python's library directory must be appended to library_dirs
             sysconfig.get_config_var('Py_ENABLE_SHARED')
             if ((sys.platform.startswith('linux') or sys.platform.startswith('gnu')
    -             or sys.platform.startswith('sunos'))
    +             or sys.platform.startswith('sunos') or sys.platform.startswith('freebsd'))
                 and sysconfig.get_config_var('Py_ENABLE_SHARED')):
                 if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
                     # building third party extensions

    I'm hoping someone will weigh in on whether this should be done on all versions of FreeBSD (I don't see why not, but perhaps there is some magic that I don't understand in newer versions).

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Jan 9, 2010

    configure.in has the same action for NetBSD*|FreeBSD*|DragonFly*, so I think distutils should parallel that. Not sure what sys.platform would be on the other BSDs, though.

    @nbastin
    Copy link
    Mannequin

    nbastin mannequin commented Jan 9, 2010

    NetBSD is netbsd* and DragonFly is dragonfly* (currently dragonfly2, although I suspect in this way dragonfly1 was identical, if it ever existed).

    @koobs
    Copy link

    koobs commented Sep 18, 2013

    Confirming identical failures on all branches:

    tip: /usr/bin/ld: cannot find -lpython3.4m
    3.3: /usr/bin/ld: cannot find -lpython3.3m
    3.2: /usr/bin/ld: cannot find -lpython3.2m
    3.1: /usr/bin/ld: cannot find -lpython3.1
    2.7: /usr/bin/ld: cannot find -lpython2.7
    2.6: /usr/bin/ld: cannot find -lpython2.6

    Tested attached patch with success, will carry this patch locally in all FreeBSD Python ports until it merged. Let's close this 5 year old nasty :)

    @koobs koobs added the stdlib Python modules in the Lib dir label Sep 18, 2013
    @koobs koobs changed the title cannot find -lpythonX.X when buinding Python on FreeBSD cannot find -lpythonX.X when building Python on FreeBSD with --enable-shared Sep 18, 2013
    @pitrou
    Copy link
    Member

    pitrou commented Sep 18, 2013

    Why special-case FreeBSD in the patch? Shouldn't this be done for nearly all Unix systems? (or, at the very least or BSD-likes)?

    @pitrou pitrou added the stdlib Python modules in the Lib dir label Sep 18, 2013
    @koobs
    Copy link

    koobs commented Sep 18, 2013

    Concur, and then also, why special case linux, gnu and sunos?

    The comment is:

    # Python's library directory [[must]] be appended to library_dirs (emphasis mine)

    Is the real question then "in what cases should the library path NOT be added?" ?

    I also note Christian used a different approach (#msg76118), electing to unconditionally add the path in setup.py

    @koobs
    Copy link

    koobs commented Sep 22, 2013

    Attaching an initial patch with the following changes:

    • Update comment
    • Add original (bpo-1600860) and current issue ID references
    • Remove sys.platform conditional
    • Remove NOOP sysconfig.get_config_var call (Reported by: birkenfeld)

    This results in all platforms receiving the same treatment as the default, which is consistent with the comment

    @pitrou
    Copy link
    Member

    pitrou commented Sep 23, 2013

    Koobs, have you signed a contributor's agreement?
    See http://www.python.org/psf/contrib/

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 28, 2013

    New changeset 48d28de5bdf8 by Antoine Pitrou in branch '3.3':
    Issue bpo-4366: Fix building extensions on all platforms when --enable-shared is used.
    http://hg.python.org/cpython/rev/48d28de5bdf8

    New changeset d6e35146ae53 by Antoine Pitrou in branch 'default':
    Issue bpo-4366: Fix building extensions on all platforms when --enable-shared is used.
    http://hg.python.org/cpython/rev/d6e35146ae53

    New changeset 28e6c23c8ae6 by Antoine Pitrou in branch '2.7':
    Issue bpo-4366: Fix building extensions on all platforms when --enable-shared is used.
    http://hg.python.org/cpython/rev/28e6c23c8ae6

    @pitrou
    Copy link
    Member

    pitrou commented Sep 28, 2013

    Ok, let's mark this bug fixed.

    @pitrou pitrou closed this as completed Sep 28, 2013
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    build The build process and cross-build stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants