Unable to compile my C Extension on Windows: unresolved external link errors

Barry Scott barry at barrys-emacs.org
Sun Nov 14 10:42:45 EST 2021


Sorry iPad sent the message before it was complete...

> On 14 Nov 2021, at 10:38, Marco Sulla <Marco.Sulla.Python at gmail.com> wrote:
> 
> Okay, now the problem seems to be another: I get the same "unresolved
> external link" errors, but only for internal functions.
> 
> This seems quite normal. The public .lib does not expose the internals
> of Python.
> The strange fact is: why can I compile it on Linux and MacOS? Their
> external libraries expose the internal functions?

Windows is not Linux is not macOS,
The toolchain on each OS has its own strengths, weaknesses and quirks.

On Windows DLLs only allow access to the symbols that are explicitly listed to be access.
On macOS .dynlib and Unix .so its being extern that does this.

> 
> Anyway, is there a way to compile Python on Windows in such a way that
> I get a shared library that exposes all the functions?

Yes you can do your own build of python that exposes the symbols you want.
But that build will be private to you and will not allow others to use your work
(on the assumption that they will not use your private build of python).

Maybe you could copy the code that you want and add it to your code?
Change any conflicting symbols of course.

Barry

> 
> On Sat, 13 Nov 2021 at 12:17, Marco Sulla <Marco.Sulla.Python at gmail.com> wrote:
>> 
>> ..... Sorry, the problem is I downloaded the 32 bit version of VS
>> compiler and 64 bit version of Python......
>> 
>> On Sat, 13 Nov 2021 at 11:10, Barry Scott <barry at barrys-emacs.org> wrote:
>>> 
>>> 
>>> 
>>>> On 13 Nov 2021, at 09:00, Barry <barry at barrys-emacs.org> wrote:
>>>> 
>>>> 
>>>> 
>>>>> On 12 Nov 2021, at 22:53, Marco Sulla <Marco.Sulla.Python at gmail.com> wrote:
>>>>> 
>>>>> It seems that on Windows it doesn't find python3.lib,
>>>>> even if I put it in the path. So I get the `unresolved external link`
>>>>> errors.
>>>> 
>>>> I think you need the python310.lib (not sure of file name) to get to the internal symbols.
>>> 
>>> Another thing that you will need to check is that the symbols you are after have been
>>> exposed in the DLL at all. Being external in the source is not enough they also have to
>>> listed in the .DLL's def file ( is that the right term?) as well.
>>> 
>>> If its not clear yet, you are going to have to read a lot or source code and understand
>>> the tool chain used on Windows to solve this.
>>> 
>>> 
>>>> 
>>>> You can use the objdump(?) utility to check that the symbols are in the lib.
>>>> 
>>>> Barry
>>> 
>>> Barry
>>> 
> 



More information about the Python-list mailing list