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
  Copy only hidden files and folders with rsync Cannondale 2 954 Mar-04-2023, 02:48 PM
Last Post: Cannondale
  Can ZipFile be used to extract hidden files? AiedailEclipsed 0 1,586 Mar-22-2022, 05:21 PM
Last Post: AiedailEclipsed
  Run hidden exe samuelbachorik 0 2,663 Aug-02-2020, 03:10 PM
Last Post: samuelbachorik
  Rock, Paper, Scissors.. Help..hidden bug xxunknownxx 4 2,607 Mar-19-2020, 02:46 AM
Last Post: jefsummers
  How to get full path of specified hidden files matching pattern recursively SriRajesh 4 3,843 Jan-18-2020, 07:12 PM
Last Post: SriRajesh
  Substitution with regular expression returns hidden character SOH bajacri 2 3,767 Nov-17-2019, 03:38 AM
Last Post: bajacri
  visibility/space of variables. Pls help. gtlhbkkj 1 1,604 Oct-12-2019, 05:51 PM
Last Post: buran
  A hidden library? BillMcEnaney 3 3,112 Apr-02-2019, 12:00 AM
Last Post: BillMcEnaney
  find hidden python files bobsmith76 4 3,254 Oct-23-2018, 10:57 PM
Last Post: wavic
  Identify Hidden rows in xls ayonsarkar 2 11,035 Apr-10-2018, 08:33 PM
Last Post: ljmetzger

Forum Jump:

User Panel Messages

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