编译Tcl包时GCC反复返回`tclStubsPtr`未定义引用错误
Tkhtml3编译报错:undefined reference to `tclStubsPtr' 解决
问题场景
在Git BASH MINGW64环境下,执行命令make -f /c/Users/billa/Documents/htmlwidget/mingw.mk编译Tcl包Tkhtml3时,控制台返回大量undefined reference to tclStubsPtr'`及相关未定义引用错误,最终编译失败。
编译错误输出
C:/ActiveTcl/lib/tclstub86.lib C:/ActiveTcl/lib/tkstub86.lib -LC:/Tcl/lib Building Tkhtml 3 COMPILE = mingw32-gcc -O2 -DNDEBUG -DUSE_TCL_STUBS=1 -DUSE_TK_STUBS=1 -IC:/ActiveTcl/include -I. -IC:/Users/billa/Documents/htmlwidget/src/ -DUSE_TCL_STUBS -DUSE_TK_STUBS TCLSH = tclsh $(BCC) C:/Users/billa/Documents/htmlwidget/tools/lemon.c -o lemon cp C:/Users/billa/Documents/htmlwidget/src/cssparse.lem . cp C:/Users/billa/Documents/htmlwidget/tools/lempar.c . $(LEMON) cssparse.lem $(COMPILE) -c cssparse.c -o cssparse.o mingw32-gcc -shared htmlparse.o htmldraw.o htmltcl.o htmlimage.o htmltree.o htmltagdb.o cssparse.o css.o cssprop.o csssearch.o htmlstyle.o htmllayout.o htmlprop.o htmlfloat.o htmlhash.o swproc.o htmlinline.o htmltable.o restrack.o cssdynamic.o htmldecode.o htmltext.o htmlutil.o "C:/ActiveTcl/lib/tclstub86.lib" "C:/ActiveTcl/lib/tkstub86.lib" -LC:/Tcl/lib -o libTkhtml3.dll htmlparse.o:htmlparse.c:(.text+0x379): undefined reference to `tclStubsPtr' htmlparse.o:htmlparse.c:(.text+0xf0a): undefined reference to `tclStubsPtr' htmlparse.o:htmlparse.c:(.text+0x101b): undefined reference to `tclStubsPtr' htmlparse.o:htmlparse.c:(.text+0x107b): undefined reference to `tclStubsPtr' htmlparse.o:htmlparse.c:(.text+0x10b0): undefined reference to `tclStubsPtr' htmlparse.o:htmlparse.c:(.text+0x10bf): more undefined references to `tclStubsPtr' follow htmldraw.o:htmldraw.c:(.text+0x14b3): more undefined references to `tclStubsPtr' follow htmldraw.o:htmldraw.c:(.text+0x3a2e): more undefined references to `tclStubsPtr' follow htmldraw.o:htmldraw.c:(.text+0x48a7): undefined reference to `tkIntXlibStubsPtr' htmldraw.o:htmldraw.c:(.text+0x4a7a): more undefined references to `tclStubsPtr' follow htmldraw.o:htmldraw.c:(.text+0x4ca8): more undefined references to `tclStubsPtr' follow htmldraw.o:htmldraw.c:(.text+0x54cb): undefined reference to `tkIntXlibStubsPtr' htmldraw.o:htmldraw.c:(.text+0x5627): more undefined references to `tkStubsPtr' follow htmltcl.o:htmltcl.c:(.text+0x11b): more undefined references to `tclStubsPtr' follow htmltcl.o:htmltcl.c:(.text+0x4c5): more undefined references to `tclStubsPtr' follow htmltcl.o:htmltcl.c:(.text+0x586): undefined reference to `tkStubsPtr' htmltcl.o:htmltcl.c:(.text+0x9f4): more undefined references to `tclStubsPtr' follow htmltcl.o:htmltcl.c:(.text+0xfba): more undefined references to `tclStubsPtr' follow htmltcl.o:htmltcl.c:(.text+0x295c): more undefined references to `tkStubsPtr' follow htmltcl.o:htmltcl.c:(.text+0x2c33): more undefined references to `tclStubsPtr' follow htmltcl.o:htmltcl.c:(.text+0x2d97): more undefined references to `tkStubsPtr' follow htmltcl.o:htmltcl.c:(.text+0x2e4f): more undefined references to `tclStubsPtr' follow htmltcl.o:htmltcl.c:(.text+0x3317): more undefined references to `tclStubsPtr' follow htmltcl.o:htmltcl.c:(.text+0x3539): more undefined references to `tclStubsPtr' follow htmlimage.o:htmlimage.c:(.text+0xb09): more undefined references to `tclStubsPtr' follow htmltree.o:htmltree.c:(.text+0x2b2): more undefined references to `tclStubsPtr' follow htmltree.o:htmltree.c:(.text+0x874): more undefined references to `tclStubsPtr' follow htmltree.o:htmltree.c:(.text+0x228c): more undefined references to `tclStubsPtr' follow htmltree.o:htmltree.c:(.text+0x3508): more undefined references to `tclStubsPtr' follow htmltree.o:htmltree.c:(.text+0x3e01): more undefined references to `tclStubsPtr' follow htmlstyle.o:htmlstyle.c:(.text+0x723): more undefined references to `tclStubsPtr' follow htmllayout.o:htmllayout.c:(.text+0x1625): more undefined references to `tclStubsPtr' follow htmllayout.o:htmllayout.c:(.text+0x3906): more undefined references to `tclStubsPtr' follow htmlprop.o:htmlprop.c:(.text+0xa77): more undefined references to `tclStubsPtr' follow htmlprop.o:htmlprop.c:(.text+0x1379): more undefined references to `tclStubsPtr' follow htmlprop.o:htmlprop.c:(.text+0x197b): more undefined references to `tclStubsPtr' follow htmlprop.o:htmlprop.c:(.text+0x3086): more undefined references to `tclStubsPtr' follow htmlprop.o:htmlprop.c:(.text+0x341b): more undefined references to `tclStubsPtr' follow htmltable.o:htmltable.c:(.text+0x3d4): more undefined references to `tclStubsPtr' follow htmltext.o:htmltext.c:(.text+0xf40): more undefined references to `tclStubsPtr' follow htmltext.o:htmltext.c:(.text+0x12d7): more undefined references to `tclStubsPtr' follow htmltext.o:htmltext.c:(.text+0x1404): more undefined references to `tclStubsPtr' follow collect2.exe: error: ld returned 1 exit status make: *** [C:/Users/billa/Documents/htmlwidget/main.mk:56: libTkhtml3.dll] Error 1
mingw.mk配置文件内容
# CC Command to invoke C compiler. # CFLAGS Flags to pass to C compiler. # SHARED_LIB Name of shared-library to build. # MKSHLIB Command to build shared library. # TCLSH Command to execute a Tcl shell. # TCLLIB Options to pass to CC to link with Tcl. # TOP Top of source tree (directory with this file in it). ##### Top of the Tkhtml source tree - the directory with this file in it. # TOP = C:/Users/billa/Documents/htmlwidget ##### BUILD can be DEBUG or RELEASE. # # BUILD = DEBUG BUILD = RELEASE HV3_POLIPO = /home/dan/work/polipo/hv3_polipo.exe ##### Version of and path to the Tcl installation to use. # TCLVERSION = 86 TCL = C:/ActiveTcl ##### Flags passed to the C-compiler to link to Tcl. # # TCLLIB = -L$(TCL)/lib -ltclstub$(TCLVERSION) -ltkstub$(TCLVERSION) TCLLIB = -L$(TCL)/lib -ltcl$(TCLVERSION) -ltk$(TCLVERSION) -ltclstub$(TCLVERSION) - ltkstub$(TCLVERSION) ##### Extra libraries used by Tcl on Linux. These flags are only required to # staticly link Tcl into an executable # # TCLLIB_DEBUG += -L/usr/X11R6/lib/ -lX11 -ldl -lm BCC = gcc CC = mingw32-gcc CFLAGS_RELEASE = -O2 -DNDEBUG CFLAGS_DEBUG = -g CFLAGS = $(CFLAGS_$(BUILD)) CFLAGS += -DUSE_TCL_STUBS=1 -DUSE_TK_STUBS=1 ##### The name of the shared library file to build. # SHARED_LIB_DEBUG = libTkhtml3g.dll SHARED_LIB_RELEASE = libTkhtml3.dll SHARED_LIB = $(SHARED_LIB_$(BUILD)) ##### Command to build a shared library from a set of object files. The # command executed will be: # # $(MKSHLIB) $(OBJS) $(TCLSTUBSLIB) -o $(SHARED_LIB) # MKSHLIB = $(CC) -shared TCLSTUBSLIB = "$(TCL)/lib/tclstub86.lib" TCLSTUBSLIB += "$(TCL)/lib/tkstub86.lib" TCLSTUBSLIB += -LC:/Tcl/lib ##### Commands to run tclsh on the build platform (to generate C files # to be passed to $(CC) from tcl scripts). # TCLSH = tclsh ##### Strip the shared library # STRIP = mingw32-strip MKSTARKIT = tclkit /home/dan/bin/sdx.kit wrap STARKITRT = /home/dan/work/tclkit-win32.upx.exe ##### Javascript libaries - libgc.a and libsee.a # JS_SHARED_LIB = libTclsee.dll JSLIB = $(HOME)/javascript/mingw/install/lib/libsee.a JSLIB += $(HOME)/javascript/mingw/install/lib/libgc.a JSFLAGS = -I$(HOME)/javascript/mingw/install/include # # End of configuration section. ########################################################################### default: binaries hv3-win32.exe: hv3_img.kit cp $(STARKITRT) starkit_runtime $(MKSTARKIT) hv3_img.bin -runtime ./starkit_runtime mv hv3_img.bin hv3-win32.exe chmod 644 hv3-win32.exe ############################################################################### include $(TOP)/main.mk
解决方法
问题根源
编译时启用了Tcl/Tk的stubs模式(通过-DUSE_TCL_STUBS=1和-DUSE_TK_STUBS=1),但链接配置存在三个问题:
- 同时混合链接了Tcl/Tk主库(
-ltcl86、-ltk86)和stubs库,导致符号冲突; - 链接路径同时指向
C:/ActiveTcl/lib和C:/Tcl/lib,可能加载到不匹配的库文件; - 编译命令中重复定义了stubs相关宏,引发潜在冲突。
修复步骤
修正链接库配置
修改mingw.mk中的TCLLIB和TCLSTUBSLIB,移除主库引用,统一使用stubs库并指向正确路径:# 替换原TCLLIB配置 TCLLIB = -L$(TCL)/lib -ltclstub$(TCLVERSION) -ltkstub$(TCLVERSION) # 替换原TCLSTUBSLIB配置 TCLSTUBSLIB = -L$(TCL)/lib -ltclstub$(TCLVERSION) -ltkstub$(TCLVERSION)清理重复编译宏
检查编译命令,移除重复的-DUSE_TCL_STUBS和-DUSE_TK_STUBS(CFLAGS中已经定义了带值的版本-DUSE_TCL_STUBS=1 -DUSE_TK_STUBS=1)。统一库路径
确保所有链接路径仅指向C:/ActiveTcl/lib,删除-LC:/Tcl/lib相关配置,避免加载错误库文件。重新编译
先清理旧编译产物,再执行编译:make clean make -f /c/Users/billa/Documents/htmlwidget/mingw.mk
内容的提问来源于stack exchange,提问作者Zamyatin
相关产品推荐
相关产品推荐

