Skip to content
Tcl Source Code View Ticket
Login

View Ticket

tclstub : interpreter uses an incompatible stubs mechanism

Closed / Invalid844b0ebe515862ee40ecffa2098d3588532fea0aCreated 2 years agoUpdated 2 years ago
Descriptionmarkdown2024-11-19 15:52:02

First of all, I'd like to point out that I'm not an expert in compilation and that the words I'm likely to use may not be the right ones. Sorry about that.

My context:

  • I'm interfacing Tcl with a program written in the Nim language.
  • I don't use autotools like the following link Building with autotools
  • OS : Windows and/or MacOS
  • Compiler : GCC and/or MSVC

Since version 9, I've been getting an error message like the one in my summary message.
On the Tcl chat I was told that it indicates an issue related to mismatched or incompatible versions of Tcl/Tk libraries.
May be a problem because I have several versions of Tcl (Tcl86 + Tcl9).

To check that my problem wasn't due to the fact that I had 2 versions installed, I ran my program via Github actions on latest Windows.

  • Init MSVC
  • Download Tcl source
  • Build Tcl with nmake
    • cd tcl9.0.0/win
    • nmake -f makefile.vc INSTALLDIR=C:/dev/Tcl90
    • nmake -f makefile.vc install INSTALLDIR=C:/dev/Tcl90
  • Install Nim
  • Compile my Nim program
  • Execute Tcl code :
    • C:/dev/Tcl90/bin/tclsh90.exe test.tcl

I got the same error message: interpreter uses an incompatible stubs mechanism

At compile time my Nim program just links the tclstub.lib (-ltclstub) library and I don't use anything else.

I'm opening this ticket because I didn't have this problem with tclstub86.lib library by using the same method.

My question:
Is the error message may be related to something else? Other than the 2 versions of Tcl installed.

jan.nijtmanswiki2024-11-20 08:45:52

I suspect that one of the Nim shared libraries was compiled with Tcl 8.6 header-files. When used with Tcl 9.0, they must be re-compiled (after some modifications) against Tcl 9.0 headers.

anonymousmarkdown2024-11-21 10:25:30

I hope I understand your response correctly.
I didn't think it could go this far !!

I'm unable to find out in which libraries the tcl.h header file may have been used and if I could miraculously figure it out, I don't even know if I could change the structure of the Nim language (but it's another problem).

I only see this librairies, there may be others:

7-zip.dll
7z.dll
boehmgc.dll
boehmgc64.dll
libcrypto-1_1-x64.dll
libcrypto-1_1.dll
libcurl.dll
libpng12.dll
libpng3.dll
libssl-1_1-x64.dll
libssl-1_1.dll
libui.dll
pcre.dll
pcre3.dll
pcre32.dll
pcre64.dll
pdcurses.dll
pdcurses32.dll
pdcurses64.dll
png.dll
SDL2.dll
SDL2_ttf.dll
sqlite3_32.dll
sqlite3_64.dll
zlib1.dll
Maybe you know these libraries ? and know if any of them use tcl.h

Thanks for the support

jan.nijtmanswiki2024-11-22 14:08:57

> Maybe you know these libraries ? and know if any of them use tcl.h

None of those use tcl.h.

Still, some library is 'load'ed from Tcl 9.0, which is compiled with Tcl 8.6 headers. The challenge is to find out which library is responsible for that.

anonymousmarkdown2024-11-25 12:46:35

Still, some library is 'load'ed from Tcl 9.0, which is compiled with Tcl 8.6 headers. The challenge is to find out which library is responsible for that.

How can I help you ?

apnadkarniplain2024-11-26 17:32:51
Nico, Can you post a link to your github action that demonstrates the issue?
anonymousmarkdown2024-11-26 20:10:02

Nico, Can you post a link to your github action that demonstrates the issue?

Github workflows Tcl 9.
Github workflows Tcl 8.6.

Thanks

jan.nijtmanswiki2024-11-26 20:42:10

interpreter uses an incompatible stubs mechanism
    while executing
"load C:/temp/pix90.dll Pix"

It helps to display the full error-message :-)

apnadkarnimarkdown2024-11-27 02:50:56

Nico,

The error occurs because the actual C function Tcl_InitStubs has changed in Tcl 9. It now takes 4 parameters, not 3 as in 8.6.

As documented for Tcl 9, the function still has only 3 parameters but these macros in tcl.h redefine to a call with 4 parameters with the fourth hardcoded as TCL_STUB_MAGIC.

So you need to change this line in your Nim definition accordingly (passing in TCL_STUB_MAGIC as the fourth parameter).

I learnt something new too :-)

/Ashok

apnadkarni Closed ticket [844b0ebe51]. [History diff]2024-12-10 10:10:23
anonymousmarkdown2024-12-11 12:44:22

Ashok,

The error occurs because the actual C function Tcl_InitStubs has changed in Tcl 9. It now takes 4 parameters, not 3 as in 8.6.

I used this value to define :

TCL_STUB_MAGIC ((int) 0xFCA3BACB + (int) sizeof(void *))

Unfortunately for me this still doesn't work, same error : "interpreter uses an incompatible stubs mechanism", where I'm surprised is that I didn't have a 'segmentation fault' rather than the usual error.

Unless tclstub.lib automatically defines this pragma : USE_TCL_STUBS I think I'm in that case in tcl.h.
If I'm right I end up with almost the same configuration defined in Tcl8.X which is defined like this in tcl8.X.h :

#ifndef USE_TCL_STUBS
#define Tcl_InitStubs(interp, version, exact) \
    Tcl_PkgInitStubsCheck(interp, version, exact)
#endif

As you well know, I don't know C and I'm learning the Nim language.
I'll try to get in contact with a Nim expert to make sure I've defined the right things.

In any case, thank you for going outside the scope of my question and looking into my code.

Thanks (again)

anonymousmarkdown2025-01-10 10:43:55

I think my torture ends today! (until the next problem!)

I know this isn't a chat room, but I wanted to keep you up to date on my project to useTcl8.6 to Tcl9 with the Nim language.

As I said in my previous messages with Tcl8.6, I just had to link this library: tclstub86.lib and nothing else.

Simply linking the library is no longer enough with Tcl/Tk9 it's a different story :

  • Include Tcl.h + tclDecls.h
  • Pass option to the C compiler : -DUSE_TCL_STUBS
  • link tclstub(90).lib

This may be normal behavior, but without using -DUSE_TCL_STUBS, I had this error : undefined reference to set up Tcl_PkgInitStubsCheck

I wanted at all costs not to use all these flags, but in the end I had to force myself to do it.

This message: "interpreter uses an incompatible stubs mechanism" was not the problem, It was different, I don't know if another message would have helped me more easily.

For the moment, I don't have a solution as simple as the one I had with Tcl8.6.

Thanks Ashok for helping me on the chat and here.
Sorry Jan for taking your time to answer this ticket.

jan.nijtmanswiki2025-01-10 11:34:05

Nicolas, I'm glad it finally worked out for you.

The stubs mechanism is implemented as macro's in tclDecls.h. So I'm surprised that it worked in Tcl 8.6 without using tclDecls.h. My guess is that you linked with tcl86.lib as well, and just called everything directly. In that case, the stub table is not used, so there is no need to initialize it with Tcl_InitStubs().

Short: In Tcl 8.6 you should have used the same method as you have now for 9.0.

Good luck!

Log in (anonymous is fine) to add a comment.