GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Undefined References when using recommended linking option: Embedding Python in C++ · Issue #93358 · python/cpython

Undefined References when using recommended linking option: Embedding Python in C++  #93358

New issue
Copy link
New issue
Copy link
Closed
Closed
Undefined References when using recommended linking option: Embedding Python in C++ #93358
Copy link
Labels
3.10 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc dirtopic-C-API

Description

@v-volatus
v-volatus
opened on May 30, 2022
Issue body actions

Documentation

URL: https://docs.python.org/3/extending/embedding.html
System: Ubuntu 22.04 using Python 3.10

Problem:

Using the recommended linking option /opt/bin/python3.10-config --ldflags leads to undefined references when compiling.

command used in terminal:

g++ $(python3.10-config --cflags ) -o 'test.o' 'test.cpp' $(python3.10-config --ldflags)

Output of python3.10-config --ldflags:

-L/usr/lib/python3.10/config-3.10-x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu -lcrypt -ldl -lm -lm

Solution:

Adding the option --embed solves the issue. By this, -lpython3.10 is also given to the compiler.

command used in terminal:

g++ $(python3.10-config --cflags ) -o 'test.o' 'test.cpp' $(python3.10-config --embed --ldflags)

output of python3.10-config --embed --ldflags:

-L/usr/lib/python3.10/config-3.10-x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu -lpython3.10 -lcrypt -ldl -lm -lm

test.cpp:


#include < Python.h >

int main()
{
	Py_Initialize();
	PyRun_SimpleString("print('Hello World from Embedded Python!!!')");
	Py_Finalize();
	
	return 0;
}

Activity

  1. v-volatus
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    on May 30, 2022
  2. v-volatus
    changed the title [-]Embedding Python in C++: Compiling and Linking under Ubuntu 22.04[/-] [+]Undefined References when using recommended linking option: Embedding Python in C++ (Ubuntu 22.04)[/+] on May 30, 2022
  3. v-volatus
    changed the title [-]Undefined References when using recommended linking option: Embedding Python in C++ (Ubuntu 22.04)[/-] [+]Undefined References when using recommended linking option: Embedding Python in C++ [/+] on May 30, 2022
  4. AA-Turner
    added
    3.10 (EOL)end of lifeend of life
    topic-C-API
    on May 30, 2022
  5. TianmingQu commented on Oct 24, 2022

    @TianmingQu
    TianmingQu
    on Oct 24, 2022 · Hidden as off-topic
    show commentMore actions
  6. erlend-aasland commented on Oct 25, 2022

    @erlend-aasland
    erlend-aasland
    on Oct 25, 2022
    Contributor
    More actions

    Adding the option --embed solves the issue. By this, -lpython3.10 is also given to the compiler.

    Yes, the docs are out of date. This was changed in Python 3.8 -- see the 3.8 What's New:

    https://docs.python.org/3/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build

    Adding --embed when producing the linker flags should help. I'll create a PR for updating the docs.

  7. erlend-aasland commented on Oct 25, 2022

    @erlend-aasland
    erlend-aasland
    on Oct 25, 2022 · Hidden as off-topic
    show commentMore actions
  8. erlend-aasland
    added 2 commits that reference this issue on Oct 25, 2022

    pythongh-93358: Fix python-config docs for how to embed Python

    6550e3b

    gh-93358: Fix python-config docs for how to embed Python (#98649)

    e063c23
  9. miss-islington
    added 2 commits that reference this issue on Oct 29, 2022

    pythongh-93358: Fix python-config docs for how to embed Python (pytho…

    53ba27c

    pythongh-93358: Fix python-config docs for how to embed Python (pytho…

    2139640
  10. erlend-aasland commented on Oct 29, 2022

    @erlend-aasland
    erlend-aasland
    on Oct 29, 2022
    Contributor
    More actions

    The docs were updated by the following PRs:

    • gh-93358: Fix python-config docs for how to embed Python #98649
    • [3.11] gh-93358: Fix python-config docs for how to embed Python (GH-98649) #98857
    • [3.10] gh-93358: Fix python-config docs for how to embed Python (GH-98649) #98858
  11. miss-islington
    added 2 commits that reference this issue on Oct 29, 2022

    gh-93358: Fix python-config docs for how to embed Python (GH-98649)

    c76e70a

    gh-93358: Fix python-config docs for how to embed Python (GH-98649)

    f8fb0d8
  12. erlend-aasland
    closed this as completedon Oct 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc dirtopic-C-API

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.