Porting a graphics library linking to xwindows and tcl/tk
Mon Aug 4 19:54:00 GMT 2008
I've posted on this earlier but I think I can ask the question more intelligently now.
I'm trying to port a graphing/plotting package (xgrafix - *not* one I wrote but one that's freely available - google "xoopic") from a typical unix tarball distribution to cygwin. I first tried what the Cygwin User's Guide suggests and ran the default configure script and resulting Makefiles. I had to redirect the X11 and XPM libraries to their respective import libraries (libX11.dll.a and libXpm.dll.a) but then the configure system worked and genreated usable Makefiles. The Makefiles ran and compiled a static library. The test programs (there is one in C and another in Fortran) compiled but they either hang or give a segmentation fault (caught under gdb) when they run.
I'm guessing this is because it made a static library (libXGC250.a) and also it might not have linked to the other libraries correctly. It also uses tcl and tk and I'm confused about those since I found tcl84.dll and tk84.dll but no corresponding import libraries such as"libtcl84.dll.a".. However, there *is* a /lib/libtcl84.a and a /lib/tk84.a. Are those the the import libraries to the DLLs or the actual archives and the developer did some clever thing using the DLL files to wrap the ".a" files into a DLL a load time? Anybody know what the deal is with the tcl/tk libraries in Cygwin and how to link to them correctly? Just an aside.
Anyway, I've tried compiling and linking by hand to make a DLL but without much success, so far. I keep having trouble getting gcc to either compile or link using just
gcc -c foo.c -lX11 -lXpm -ltcl -ltk (sometimes including things like -L/lib -L/usr/X11R6/lib) -------- to compile
gcc -shared -o libXGC.dll foo1.o ... -lX11 -lXpm -ltcl -ltk ------------ to link
(Sorry I don't have the error messages handy at the moment.)
I realize I also need to make an import library also but I haven't even gotten this far yet.
Since "make" did create static libraries I thought it would be useful to examine the command lines it spit out to compile and link. Here's one of the compile lines that the Makefile produced
gcc -DHAVE_CONFIG -I. -I/usr/inclde -I/usr/include -DXGTCL=\"/usr/local/xgrafix/lib\" -I/usr/X11R6/include -Wall -Wno-unused -g DDEBUG -DXPMENABLED -DTcl75_Tk41 -DHAVE_CONVERT -DHAVE_CONVERT -c xgxommands.c
The rest are the same except for the source. I don't know why it has two identical include options and two -DHAVE_CONVERT options but I assume it can't hurt anything.
The linking lines for the main library (there were a couple of others) used "ar" instead of gcc or ld. Here they are:
ar cr libXGC250.a xgpaint2d.o xgpaint3d.o xgprint.o xgsetup.o xgcommands.o xginitvar.o xgpaint3d.o .... etc ------- nothing else but object files here.
I understand that this will just make a static library. Also it doesn't have any "T _" entries when you run nm on it, so I assume this means it doesn't have the right kind of table to make a DLL directly from the archive by just using dlltool. I think the Makefiles are just providing a simple generic safe build that will work under most unix systems but won't under Cygwin. I don't know if I'll be able to modify the Makefiles or configure system easily so I may just need to build it all by hand. But at least there aren't a huge number of source files spread all over the place.
So how do I change things so that I can make a library that I can run under Cygwin-X? Unless somebody knows of some simple modifcations to the Makefiles I can make that will automatically build everything right, my best bet is probably to just do it all by hand. Can anybody provide some advice on how to do this? Should I try to convert the static library to a DLL, using the linker or the dlltool, or should I try to link the existing object files with gcc or ld, or should I simply start from scratch, recompile the source code in gcc and then link? Are my gcc command lines shown above (the first ones - the ones I tried) missing anything important or including something they shouldn't? I'd really appreciate if somebody could point me in the right direction here. This is my first attempt at a port to Cygwin.
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
More information about the Cygwin-xfree