Details
-
Type:
Bug
-
Status: Closed (View Workflow)
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: core
-
Labels:None
-
Environment:
winxp+cygwin
Description
src/utilfuns/swobject.cpp uses stricmp(). this is not standard ANSI C and causes a compile failure in cygwin because cygwin libc does not provide a compatibility hook for it, as does glibc. however, cygwin does provide <string.h> which helpfully #defines stricmp to strcasecmp, which is the ANSI C standard name for that function.
an update was attempted in mid-march (see sword-devel archives):
> In utilstr.h in the namespace sword we have our own
> stricmp. i changed swobject to use that instead.
this simply moved the flaw from a compilation error to a link error. for building gnomesword under cygwin, the sword build process does this to correct the problem on the fly:
mv src/utilfuns/swobject.cpp src/utilfuns/swobject.cpp.ORIG
sed < src/utilfuns/swobject.cpp.ORIG \
-e 's/<utilstr.h>/&\n#include <string.h>/' \
-e 's/sword::stricmp/stricmp/' \
> src/utilfuns/swobject.cpp
this corrects the problem, but is nothing but a hack.
corrections available:
[a] replace all use of stricmp with strcasecmp.
short of that,
[b] remove the attempted fix (2nd -e expression hack fix) and make swobject.cpp #include <string.h>.
correction [a] is vastly to be preferred, because it is Correct, whereas the both the current state of the code and correction [b] constitute nothing more than crude hacks.
There is no problem with the code, as far as I can see. It seems to be a problem with autotools on cygwin (however unlikely that seems). I am horrible at autotools but it looks like in sword/Makefile.am, we are adding libsword.la correctly to the target buildtest.cpp. But for some reason, the compile fails like this:
/bin/sh ./libtool --tag=CXX --mode=link g++ -O2 -I/usr/include -DUSELUCENE -o buildtest.exe buildtest.o ./lib/libsword.la -lz -L/usr/lib -lclucene
.text+0x2b): undefined reference to `sword::stricmp(char const*, char const*)'
g++ -O2 -I/usr/include -DUSELUCENE -o buildtest.exe buildtest.o ./lib/.libs/libsword.a -L/usr/lib -lz /usr/lib/libclucene.a
./lib/.libs/libsword.a(swobject.o):swobject.cpp
collect2: ld returned 1 exit status
When experimenting and changing the compile like to what is below, things link ok:
g++ -O2 -I/usr/include -DUSELUCENE -o buildtest.exe buildtest.o -L/usr/lib -lz /usr/lib/libclucene.a -Llib/.libs -lsword -lclucene -lz
I think libtool might be broken on cygwin. Dunno.
Anyway, could someone double-check we are doing things correctly in Makefile.am and then see if there is an 'almost' correct way to do things to work around this problem on cygwin? Thanks for any time and info you can contribute. Thank you to charcoal for experimenting with me to get the above information.