Macaulay2 / M2

The primary source code repository for Macaulay2, a system for computing in commutative algebra, algebraic geometry and related fields.
https://macaulay2.com
340 stars 228 forks source link

ForeignFunctions example error with libmps #3374

Open mahrud opened 1 month ago

mahrud commented 1 month ago

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

d-torrance commented 1 month ago

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.

mahrud commented 1 month ago

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?

d-torrance commented 1 month ago

It is required for the unversioned libmps.so.

d-torrance commented 1 month ago

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.

mahrud commented 1 month ago

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!

mahrud commented 1 month ago

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.

d-torrance commented 1 month ago

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.

mahrud commented 4 weeks ago

(Not trying to rush you, I'm just going around assigning issues to people just to figure out which issues have no ownership)