M2
M2 copied to clipboard
ForeignFunctions example error with libmps
This is happening on Debian 12.6:
$ cat usr-dist/common/share/doc/Macaulay2/ForeignFunctions/example-output/_foreign__Symbol.errors
-- -*- M2-comint -*- hash: 2759357810293599536
i1 : mps = openSharedLibrary "mps"
o1 = mps
o1 : SharedLibrary
i2 : cplxT = foreignStructType("cplx_t", {"r" => double, "i" => double})
o2 = cplx_t
o2 : ForeignStructType
i3 : foreignSymbol(mps, "cplx_i", cplxT)
o3 = HashTable{"i" => 1}
"r" => 0
o3 : ForeignObject of type cplx_t
i4 : foreignSymbol("cplx_i", cplxT)
stdio:4:1:(3): error: /net/st1/export/clusterhome/sayrafi/M2/M2/BUILD/build/usr-dist/x86_64-Linux-Debian-12/bin/M2-binary: undefined symbol: cplx_i
Here is the library file:
dpkg -S /usr/lib/x86_64-linux-gnu/libmps.so.3
libmps3:amd64: /usr/lib/x86_64-linux-gnu/libmps.so.3
cc: @d-torrance
Am I correct in assuming that M2 was linked with mpsolve as a static instead of dynamic library for this build?
This is a long standing issue -- see also #2919. I should probably just use a different example for foreignSymbol.
mpsolve was built by our build script and linked statically, but there are shared libraries available:
$ find /usr/lib/x86_64-linux-gnu/libmps*
/usr/lib/x86_64-linux-gnu/libmps.so.3
/usr/lib/x86_64-linux-gnu/libmps.so.3.0.1
libmps-dev is not installed, but that shouldn't be required, right?
It is required for the unversioned libmps.so.
But the issue is that the 2-argument foreignSymbol looks for symbols in the dynamic libraries that M2 is already linked against. And if we link against mpsolve statically, then it won't find cplx_i.
Oh, I see.
It is required for the unversioned
libmps.so.
I did make a symlink of a libmps.so.3 to .local/lib/libmps.so!
I'm happy to either close this or keep it open until you use a different example for foreignSymbol. What is a library that we're always dynamically linked with? I can't think of an obvious choice.
Let's keep it open. I couldn't think of a better example back when I wrote this documentation, but there certainly might be one.
(Not trying to rush you, I'm just going around assigning issues to people just to figure out which issues have no ownership)