Python Forum
PyMODINIT_FUNC and gcc hidden visibility
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyMODINIT_FUNC and gcc hidden visibility
#1
Hello all,

I have a question about an exernal module I'm writing. I'm following the official tutorial at this page: https://docs.python.org/3/extending/extending.html

The question is simple. The tutorial says that I have to use PyMODINIT_FUNC to define a "startup" function that registers the module. Compiling the skeleton module with a basic setup.py works perfectly fine.

When I add the flag "-fvisibility=hidden" (see https://gcc.gnu.org/wiki/Visibility) to the compilation flags the PyMODINIT_FUNC function disappears, so the external module can't be imported anymore and this is the error:

Quote:ImportError: dynamic module does not define module export function (PyInit_pyopenvg)

Digging into Python C headers, I found the PyMODINIT_FUNC definition in /usr/include/python3.6/pyport.h; changing the definition from:
define PyMODINIT_FUNC extern "C" PyObject*
to
define PyMODINIT_FUNC extern "C" __attribute__ ((visibility("default"))) PyObject*
the module imports and works fine.
Now I'm aware this is a hack, but I'm wondering which is the right way to have visibility set to hidden and export correctly the module init function
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python - Hidden Text / Html Mail python1337 1 2,275 Feb-08-2025, 10:47 AM
Last Post: python1337
  Copy only hidden files and folders with rsync Cannondale 2 2,236 Mar-04-2023, 02:48 PM
Last Post: Cannondale
  Can ZipFile be used to extract hidden files? AiedailEclipsed 0 2,360 Mar-22-2022, 05:21 PM
Last Post: AiedailEclipsed
  Run hidden exe samuelbachorik 0 3,496 Aug-02-2020, 03:10 PM
Last Post: samuelbachorik
  Rock, Paper, Scissors.. Help..hidden bug xxunknownxx 4 3,440 Mar-19-2020, 02:46 AM
Last Post: jefsummers
  How to get full path of specified hidden files matching pattern recursively SriRajesh 4 5,142 Jan-18-2020, 07:12 PM
Last Post: SriRajesh
  Substitution with regular expression returns hidden character SOH bajacri 2 4,773 Nov-17-2019, 03:38 AM
Last Post: bajacri
  visibility/space of variables. Pls help. gtlhbkkj 1 2,209 Oct-12-2019, 05:51 PM
Last Post: buran
  A hidden library? BillMcEnaney 3 4,102 Apr-02-2019, 12:00 AM
Last Post: BillMcEnaney
  find hidden python files bobsmith76 4 4,411 Oct-23-2018, 10:57 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020