Overview
| Artifact ID: | a42f1c411fd8c5b17016bcba762ac6fb2d9177b7c2deae77ab3b1d2692a5fcc2 |
|---|---|
| Ticket: | 4663e0636f7a24b9363e67c7a3dd25e9e495be17
TIP 538 and Tcl extensions: 'tommath.h' file not found |
| User & Date: | jan.nijtmans on 2020-05-18 13:42:09 |
Changes
- icomment:
Thanks, Stefan, for this report. The first problem with TIP #538 is that <tommath.h> is binary incompatible in Tcl 8.7 compared to Tcl 8.6. This is mainly due to Tcl's bad decision to make the mp_digit type 32-bit always: On 64bit platforms this is not optimal, and it's different from how libtommath's build scripts work. So, TIP #538 fixes this: The libtommath included by Tcl is now binary compatible with an externally-built libtommath. The recommended way for extensions would be to do the same thing as Tcl does. So, if Tcl is compiled against an external libtommath, the extension should be linked to that external libtommath as well. There is a symbol TCL_WITH_EXTERNAL_TOMMATH you can use to detect the difference. On many Linux systems (e.g. Ubuntu 20.4 LTS, Focal Fossa) libtommath can be used by "sudo apt-get install libtommath-dev". That shouldn't be too difficult. I expect that Tcl 8.7 - once included in Ubunto - will use this libtommath in stead of it's own version. So, nsf.c should do: <pre> ifdef TCL_WITH_EXTERNAL_TOMMATH # include <tommath.h> #else # include <tclTomMath.h> #endif </pre> and later in the code: <pre> #ifndef TCL_WITH_EXTERNAL_TOMMATH if (Tcl_TomMath_InitStubs(interp, "8.5") == NULL) { return TCL_ERROR; } #endif </pre> When linking the library, use "-ltommath" as additional link option. Of course, NSF could decide to keep it as-is, no problem. The only limitation is that using <tclTommath.h>, only the functions included by Tcl are usable. Using <tommath.h> the full list of libtommath functions can be used. So, in the long run, using an external libtommath is better always. That doesn't solve the problem described here. Well, Tcl doesn't install <tommath.h> because it could lead to a conflict with the official libtommath version. So, if you want to use the Tcl-provided libtommath, one way to do that is add a "compat" directory to NSF and put Tcl's <tommath.h> there. Just add "-I ../compat" to the compiler options and everything should work. It would have been nice when Tcl could provide the "mp_int" type from tcl.h. But that would cause a conflict between tcl.h and the external tommath.h. A tiny patch to tommath.h would fix this (See [https://github.com/libtom/libtommath/pull/473|See libtommath's PR 473]), but this PR was rejected with the remark: "No, such patches, which are only useful for Tcl won't happen.". The tommath.h provided in NSF's "/compat" directory could be a stripped-down version, if you like. Only providing "mp_int" and "mp_digit" is already enough (I didn't test that). Hope this helps. I'll keep this ticket open, so you can ask more questions if you like. That could be useful for other extensions too. - login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"