Unable to compile my C Extension on Windows: unresolved external link errors
Eryk Sun
eryksun at gmail.com
Mon Nov 15 14:50:37 EST 2021
On 11/14/21, Marco Sulla <Marco.Sulla.Python at gmail.com> wrote:
> On Sun, 14 Nov 2021 at 16:42, Barry Scott <barry at barrys-emacs.org> wrote:
>
>> On macOS .dynlib and Unix .so its being extern that does this.
>
> And extern is the default. I understand now.
Per Include/exports.h and Include/pyport.h, Python should be built in
Unix with "default" visibility (per global/local binding) for the API
PyAPI_FUNC(RTYPE) and PyAPI_DATA(RTYPE) symbols. Everything else with
global binding will be hidden via the "-fvisibility=hidden" compiler
option that's configured in the makefile. For example:
$ readelf -s Objects/dictobject.o | grep HIDDEN | cut -b 40-
GLOBAL HIDDEN 4 _pydict_global_version
GLOBAL HIDDEN 1 _PyDict_ClearFreeList
GLOBAL HIDDEN 1 _PyDict_Fini
GLOBAL HIDDEN 1 _PyDictKeys_StringLookup
GLOBAL HIDDEN 9 _Py_dict_lookup
GLOBAL HIDDEN 1 _PyDict_GetItemHint
GLOBAL HIDDEN 1 _PyDict_LoadGlobal
GLOBAL HIDDEN 1 _PyDict_Pop_KnownHash
GLOBAL HIDDEN 1 _PyDict_FromKeys
GLOBAL HIDDEN 1 _PyDict_KeysSize
GLOBAL HIDDEN 1 _PyDict_NewKeysForClass
GLOBAL HIDDEN 1 _PyObject_InitializeDict
GLOBAL HIDDEN 1 _PyObject_MakeDictFromIns
GLOBAL HIDDEN 1 _PyObject_StoreInstanceAt
GLOBAL HIDDEN 1 _PyObject_GetInstanceAttr
GLOBAL HIDDEN 1 _PyObject_IsInstanceDictE
GLOBAL HIDDEN 1 _PyObject_VisitInstanceAt
GLOBAL HIDDEN 1 _PyObject_ClearInstanceAt
GLOBAL HIDDEN 1 _PyObject_FreeInstanceAtt
GLOBAL HIDDEN 1 _PyObjectDict_SetItem
GLOBAL HIDDEN 1 _PyDictKeys_DecRef
GLOBAL HIDDEN 1 _PyDictKeys_GetVersionFor
These hidden symbols get linked in the executable or shared-object
with local binding. For example:
$ readelf -s python | grep _PyDict_FromKeys | cut -b 40-
LOCAL DEFAULT 16 _PyDict_FromKeys
I suggest testing your project with Python built as a shared library,
i.e. --enable-shared. The local binding on internal symbols may be a
problem in this case.
More information about the Python-list
mailing list