Python version: 3.7.4 but it affects all versions of python I try building the library for
Operating System: Ubuntu 16.04
pythonnet installed inside a virtualenv
Details
Importing the clr library results in an import error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: /usr/lib/libmonosgen-2.0.so.1 undefined symbol: _ZTIPi
Minimal example:
importclr
This had been working just fine, however it looks like libmonosgen-2.0.so.1 updated on the 9th and I think that's what is the cause of this issue. Rebuilding completely from scratch in a fresh virtualenv doesn't fix this problem.
It doesn't work for me with older versions of mono:
# rpm -qa | grep mono
mono-extras-5.20.1.19-0.xamarin.3.epel7.x86_64
mono-devel-5.20.1.19-0.xamarin.3.epel7.x86_64
libmono-llvm0-5.20.1.19-0.xamarin.3.epel7.x86_64
mono-web-5.20.1.19-0.xamarin.3.epel7.x86_64
mono-winforms-5.20.1.19-0.xamarin.3.epel7.x86_64
mono-data-5.20.1.19-0.xamarin.3.epel7.x86_64
mono-core-5.20.1.19-0.xamarin.3.epel7.x86_64
libmonosgen-2_0-1-6.4.0.198-0.xamarin.3.epel7.x86_64
mono-winfxcore-5.20.1.19-0.xamarin.3.epel7.x86_64
mono-wcf-5.20.1.19-0.xamarin.3.epel7.x86_64
mono-data-oracle-5.20.1.19-0.xamarin.3.epel7.x86_64
mono-llvm-tools-6.0+mono20190708165219-0.xamarin.1.epel7.x86_64
mono-mvc-5.20.1.19-0.xamarin.3.epel7.x86_64
mono-data-sqlite-5.20.1.19-0.xamarin.3.epel7.x86_64
# python -c 'import clr'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: /lib64/libmonosgen-2.0.so.1: undefined symbol: _ZTIPi
# uname -a
Linux pp-mag604.uk8.scp.bskyb.com 3.10.0-1062.4.1.el7.x86_64 #1 SMP Fri Oct 18 17:15:30 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
# python -V
Python 2.7.5
# pip show pythonnet
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Name: pythonnet
Version: 2.4.0
Summary: .Net and Mono integration for Python
Home-page: https://pythonnet.github.io/
Author: The Python for .Net developers
Author-email: pythondotnet@python.org
License: MIT
Location: /usr/lib64/python2.7/site-packages
Requires:
Required-by:
libmonosgen-2_0-1-6.4.0.198-0.xamarin.3.epel7.x86_64 is the problem, this will not work (if you don't compile things yourself). I don't know why different C++ ABIs are used here but I also have no capacities to debug this.
Is that still an issue? I just ran into this using pythonnet 2.4 with a dotnetcore2.0 build and having latest mono-devel installed which is, at time of writing, 6.8.0.
Reacted by Mikhail Stolyarov, Mark Adamson, Andrew D. McGuire and ChristophII
I think I figured out the root cause, but don't know yet what is the proper way to fix it: mono/mono#19628
TL;DR; properly linking libmono from Mono 6.8 requires C++ linker or to manually specify C++ stdlib to be linked with C linker (e.g. -lstdc++). I believe workaround is to manually add -lstdc++ to setup.py like this:
Activity
jj-tetraquark commented on Aug 13, 2019
Looks like this is the same issue as is being discussed here #925 (comment)
Temporary workaround is to revert and pin mono to 5.20.1
antivirtel commented on Nov 15, 2019
It doesn't work for me with older versions of mono:
Tried with older version as well, didn't work:
How can I make it work?
filmor commented on Nov 15, 2019
libmonosgen-2_0-1-6.4.0.198-0.xamarin.3.epel7.x86_64 is the problem, this will not work (if you don't compile things yourself). I don't know why different C++ ABIs are used here but I also have no capacities to debug this.
antivirtel commented on Nov 15, 2019
Thanks @filmor, I didn't notice that package had higher version, now it works, thanks.
bneumann commented on Jan 28, 2020
Is that still an issue? I just ran into this using pythonnet 2.4 with a dotnetcore2.0 build and having latest mono-devel installed which is, at time of writing, 6.8.0.
lostmsu commented on Apr 22, 2020
I think I figured out the root cause, but don't know yet what is the proper way to fix it: mono/mono#19628
TL;DR; properly linking libmono from Mono 6.8 requires C++ linker or to manually specify C++ stdlib to be linked with C linker (e.g. -lstdc++). I believe workaround is to manually add -lstdc++ to setup.py like this:
I'll wait for Mono response to give us a supported way to do this.
lostmsu commented on Apr 22, 2020
Aaaand after getting pythonnet successfully install with this workaround I hit #1034
filmor commented on Apr 22, 2020
The C++ linker does a bit more than just -lstdc++, it's probably enough to just use language="c++" in the Extension constructor.
filmor commented on Apr 23, 2020
And the module functions need to be extern "C".