From: Perrog <pe...@gm...> - 2007-02-08 06:25:19
|
Hi! I'm trying to build an TCL/Tk extension. I manage to build it completely, albeit some linker warnings about multiple definition, but when I run a sample script I get a segmentation fault when the C source calls X-windows routines. This is a sample GDB session: /src/gnu-src/nxtvepg-2.7.7> gdb build-powerpc/nxtvepg GNU gdb 6.3.50-20050815 (Apple version gdb-573) (Fri Oct 20 15:54:33 GMT 2006) <copyleft cutted> This GDB was configured as "powerpc-apple-darwin"...Reading symbols for shared libraries ...... done (gdb) run Starting program: /src/gnu-src/nxtvepg-2.7.7/build-powerpc/nxtvepg Reading symbols for shared libraries ...................................................................+....+ done Reading symbols for shared libraries . done Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x732e2078 0x0004d718 in wm_detect (dpy=0x68a008) at epgui/wmhooks.c:254 254 Window root = DefaultRootWindow(dpy); (gdb) bt #0 0x0004d718 in wm_detect (dpy=0x68a008) at epgui/wmhooks.c:254 #1 0x0004daf0 in WmHooks_Init (interp=0x2fd608) at epgui/wmhooks.c:488 #2 0x000434a4 in main (argc=1, argv=0x16f74c) at epgui/epgmain.c:3015 (gdb) list 249 #define INIT_ATOM(dpy,atom) atom = XInternAtom(dpy,#atom,False) 250 251 static void 252 wm_detect(Display *dpy) 253 { 254 Window root = DefaultRootWindow(dpy); 255 256 INIT_ATOM(dpy, _NET_SUPPORTED); 257 INIT_ATOM(dpy, _NET_WM_STATE); 258 INIT_ATOM(dpy, _NET_WM_STATE_STAYS_ON_TOP); (gdb) I'm trying to deduce the error and think this has to do with the linker warnings. Partly because I experience a similar event (not related to Tcl!), partly because I don't know otherwise. In more detail, the linker warns about multiple definitions of X11-functions. And I think Tk.framework is linked against the static X11-libray, but my extension links against a shared X11-library (perhaps newer.) And I can't just strip away -lX11 and -lXmu because then linking fails with undefined symbols XFree, XGetErrorText, XGetWindowAttributes, XmuClientWindow. What shall I do to make it work? May I need to rebuilt the "TclTkAquaBI" or Tk.framework and link against shared X11 library? Is there already a such pre-built binary? Back to the linker warning. It looks like $ cc -o build-powerpc/nxtvepg $(OBJS) -L/usr/local/lib -L/usr/X11R6/lib -framework tk -framework tcl -lm -lX11 -lXmu -lpthread /usr/bin/ld: warning multiple definitions of symbol _XGetGeometry /Library/Frameworks/tk.framework/tk(single module) definition of _XGetGeometry /usr/X11R6/lib/libX11.dylib(GetGeom.o) definition of _XGetGeometry ... /usr/bin/ld: warning multiple definitions of symbol _XSetErrorHandler /Library/Frameworks/tk.framework/tk(single module) definition of _XSetErrorHandler /usr/X11R6/lib/libX11.dylib(ErrHndlr.o) definition of _XSetErrorHandler And I can check what shared libraries Tk framework is linked against with otool: $ otool -L /System/Library/Frameworks/Tk.framework/Versions/8.4/Tk /System/Library/Frameworks/Tk.framework/Versions/8.4/Tk: /System/Library/Frameworks/Tk.framework/Versions/8.4/Tk (compatibility version 8.4.0, current version 8.4.0) /System/Library/Frameworks/Tcl.framework/Versions/8.4/Tcl (compatibility version 8.4.0, current version 8.4.0) /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 128.0.0) /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 22.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.0.0) The WmHooks_Init function that calls wm_detect() above in the GDB session, look like this: void WmHooks_Init( Tcl_Interp * interp ) { #ifndef WIN32 Tk_Window tkwin; Display * dpy; tkwin = Tk_MainWindow(interp); if (tkwin != NULL) { dpy = Tk_Display(tkwin); if (dpy != NULL) { wm_detect(dpy); } } #endif Tcl_CreateCommand(interp, "C_Wm_StayOnTop", WmHooks_StayOnTop, (ClientData) NULL, NULL); Tcl_CreateCommand(interp, "C_Wm_SetIcon", WmHooks_SetIcon, (ClientData) NULL, NULL); } Thanks for any helps, in advance. Regards, Roger |