EarthScope / slinktool

Other
18 stars 15 forks source link

Compile caveat, remove C99 ‘for’ loop initial declarations #1

Closed DonRhodes closed 1 year ago

DonRhodes commented 6 years ago

To compile the slinktool in Debian/Ubuntu (only distributions I have tried) I have needed to add CFLAGS="-std=c99" to ezxml/Makefile.

Putting this here in hopes of it being useful to someone in the future / maybe that could be added to the ReadMe install instructions as a 'you may need to do this'.

chad-earthscope commented 6 years ago

@cudonrhodes could you share the error/warning you were getting and platform details that required adding "-std=c99" to CFLAGS? I have Ubuntu 16.04 with gcc 5.4.0 and there are no build warnings or errors.

Normally, CFLAGS is something set by the user or build environment and only the most portable, i.e. supported by all reasonable targets, things should be hardcoded. I'm hopeful we can determine why such a flag is needed and fix the root cause instead of hard-coding or requiring such flags on various platforms.

Thanks for reporting this.

DonRhodes commented 6 years ago

Sorry for the long delay on this! I should have included the error with the original post.

This was the process I used and the error that came up.

$ git clone https://github.com/iris-edu/slinktool.git $cd slinktool

$ make Running make all in libslink make[1]: Entering directory '/home/user/seedlink/slinktool/libslink' cc -c gswap.c -o gswap.o cc -c unpack.c -o unpack.o cc -c msrecord.c -o msrecord.o cc -c genutils.c -o genutils.o cc -c strutils.c -o strutils.o cc -c logging.c -o logging.o cc -c network.c -o network.o cc -c statefile.c -o statefile.o cc -c config.c -o config.o cc -c globmatch.c -o globmatch.o cc -c slplatform.c -o slplatform.o cc -c slutils.c -o slutils.o rm -f libslink.a ar -crs libslink.a gswap.o unpack.o msrecord.o genutils.o strutils.o logging.o network.o statefile.o config.o globmatch.o slplatform.o slutils.o make[1]: Leaving directory '/home/user/seedlink/slinktool/libslink' Running make all in ezxml make[1]: Entering directory '/home/user/seedlink/slinktool/ezxml' cc -c ezxml.c ezxml.c: In function ‘ezxml_toxml_r’: ezxml.c:725:5: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode for (size_t d = 0; d < depth; ++d) ^ ezxml.c:725:5: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code ezxml.c:760:13: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode for (size_t d = 0; d < depth; ++d) ^ Makefile:22: recipe for target 'ezxml.o' failed make[1]: [ezxml.o] Error 1 make[1]: Leaving directory '/home/user/seedlink/slinktool/ezxml' Running make all in src make[1]: Entering directory '/home/user/seedlink/slinktool/src' cc -I../libslink -I../ezxml -c dsarchive.c -o dsarchive.o cc -I../libslink -I../ezxml -c archive.c -o archive.o cc -I../libslink -I../ezxml -c slinkxml.c -o slinkxml.o cc -I../libslink -I../ezxml -c slinktool.c -o slinktool.o cc -o ../slinktool dsarchive.o archive.o slinkxml.o slinktool.o -L../libslink -L../ezxml -lslink -lezxml /usr/bin/ld: cannot find -lezxml collect2: error: ld returned 1 exit status Makefile:28: recipe for target '../slinktool' failed make[1]: [../slinktool] Error 1 make[1]: Leaving directory '/home/user/seedlink/slinktool/src' Makefile:5: recipe for target 'all' failed make: *** [all] Error 2

chad-earthscope commented 6 years ago

Thanks @cudonrhodes. That looks easy to fix in the code and then no CFLAGS modifications are needed.

I'm curious what version of Debian/Ubuntu and C compiler you are using, since I didn't get those errors on my Ubuntu system.

DonRhodes commented 6 years ago

I tried it on:

$ cat /etc/os-release NAME="Ubuntu" VERSION="17.04 (Zesty Zapus)"

$ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 6.3.0-12ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 6.3.0 20170406 (Ubuntu 6.3.0-12ubuntu2)

and:

$ cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 8 (jessie)" NAME="Debian GNU/Linux" VERSION_ID="8" VERSION="8 (jessie)" ID=debian HOME_URL="http://www.debian.org/" SUPPORT_URL="http://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"

$ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 4.9.2-10' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.9 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --with-arch-32=i586 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.9.2 (Debian 4.9.2-10)

geoffdavis commented 5 years ago

@chad-iris I'm getting the same issue on:

ezxml.c:725:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
     for (size_t d = 0; d < depth; ++d)
     ^
ezxml.c:725:5: note: use option -std=c99 or -std=gnu99 to compile your code
ezxml.c:760:13: error: ‘for’ loop initial declarations are only allowed in C99 mode

▽
             for (size_t d = 0; d < depth; ++d)
             ^
make[1]: *** [ezxml.o] Error 1

GCC version info:

davis@anfdevl ~/src/IGPP/slinktool (master)$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
geoffdavis commented 5 years ago

To further this point - if I just set the CFLAGS environment variable to -std=c99, the compilation process for libslink fails, and we never even get to ezxml:

davis@anfdevl ~/src/IGPP/slinktool (master)$ CFLAGS=-std=c99 make
Running make all in libslink
make[1]: Entering directory `/home/davis/src/IGPP/slinktool/libslink'
cc -std=c99 -c gswap.c -o gswap.o
cc -std=c99 -c unpack.c -o unpack.o
cc -std=c99 -c msrecord.c -o msrecord.o
cc -std=c99 -c genutils.c -o genutils.o
cc -std=c99 -c strutils.c -o strutils.o
cc -std=c99 -c logging.c -o logging.o
cc -std=c99 -c network.c -o network.o
network.c: In function ‘sl_sayhello’:
network.c:895:3: warning: implicit declaration of function ‘strncasecmp’ [-Wimplicit-function-declaration]
   if (ret != 2 || strncasecmp (servid, "SEEDLINK", 8))
   ^
cc -std=c99 -c statefile.c -o statefile.o
cc -std=c99 -c config.c -o config.o
cc -std=c99 -c globmatch.c -o globmatch.o
cc -std=c99 -c slplatform.c -o slplatform.o
slplatform.c: In function ‘slp_getaddrinfo’:
slplatform.c:187:19: error: storage size of ‘hints’ isn’t known
   struct addrinfo hints;
                   ^
slplatform.c:194:3: warning: implicit declaration of function ‘getaddrinfo’ [-Wimplicit-function-declaration]
   if ((rv = getaddrinfo (nodename, nodeport, &hints, &result)))
   ^
slplatform.c:199:44: error: dereferencing pointer to incomplete type
   for (ptr = result; ptr != NULL; ptr = ptr->ai_next)
                                            ^
slplatform.c:201:12: error: dereferencing pointer to incomplete type
     if (ptr->ai_family == AF_INET)
            ^
slplatform.c:203:24: error: dereferencing pointer to incomplete type
       memcpy (addr, ptr->ai_addr, sizeof (struct sockaddr));
                        ^
slplatform.c:204:29: error: dereferencing pointer to incomplete type
       *addrlen = (size_t)ptr->ai_addrlen;
                             ^
slplatform.c:209:3: warning: implicit declaration of function ‘freeaddrinfo’ [-Wimplicit-function-declaration]
   freeaddrinfo (result);
   ^
slplatform.c: In function ‘slp_usleep’:
slplatform.c:332:19: error: storage size of ‘treq’ isn’t known
   struct timespec treq, trem;
                   ^
slplatform.c:332:25: error: storage size of ‘trem’ isn’t known
   struct timespec treq, trem;
                         ^
slplatform.c:337:3: warning: implicit declaration of function ‘nanosleep’ [-Wimplicit-function-declaration]
   nanosleep (&treq, &trem);
   ^
make[1]: *** [slplatform.o] Error 1
make[1]: Leaving directory `/home/davis/src/IGPP/slinktool/libslink'
Running make all in ezxml
make[1]: Entering directory `/home/davis/src/IGPP/slinktool/ezxml'
cc -std=c99 -c ezxml.c
rm -f libezxml.a
ar -csq libezxml.a ezxml.o
make[1]: Leaving directory `/home/davis/src/IGPP/slinktool/ezxml'
Running make all in src
make[1]: Entering directory `/home/davis/src/IGPP/slinktool/src'
cc -std=c99 -I../libslink -I../ezxml -c dsarchive.c -o dsarchive.o
dsarchive.c: In function ‘ds_getstream’:
dsarchive.c:371:5: warning: implicit declaration of function ‘strdup’ [-Wimplicit-function-declaration]
     foundstream->defkey  = strdup (defkey);
     ^
dsarchive.c:371:26: warning: assignment makes pointer from integer without a cast [enabled by default]
     foundstream->defkey  = strdup (defkey);
                          ^
cc -std=c99 -I../libslink -I../ezxml -c archive.c -o archive.o
cc -std=c99 -I../libslink -I../ezxml -c slinkxml.c -o slinkxml.o
cc -std=c99 -I../libslink -I../ezxml -c slinktool.c -o slinktool.o
slinktool.c: In function ‘main’:
slinktool.c:87:20: error: storage size of ‘sa’ isn’t known
   struct sigaction sa;
                    ^
slinktool.c:89:17: error: ‘SA_RESTART’ undeclared (first use in this function)
   sa.sa_flags = SA_RESTART;
                 ^
slinktool.c:89:17: note: each undeclared identifier is reported only once for each function it appears in
slinktool.c:90:3: warning: implicit declaration of function ‘sigemptyset’ [-Wimp
▽
  5 ¬
licit-function-declaration]
   sigemptyset (&sa.sa_mask);
   ^
slinktool.c:93:3: warning: implicit declaration of function ‘sigaction’ [-Wimplicit-function-declaration]
   sigaction (SIGINT, &sa, NULL);
   ^
slinktool.c: In function ‘parameter_proc’:
slinktool.c:635:5: warning: implicit declaration of function ‘strdup’ [-Wimplicit-function-declaration]
     slconn->begin_time = strdup (timeptr->element);
     ^
slinktool.c:635:24: warning: assignment makes pointer from integer without a cast [enabled by default]
     slconn->begin_time = strdup (timeptr->element);
                        ^
slinktool.c:641:24: warning: assignment makes pointer from integer without a cast [enabled by default]
       slconn->end_time = strdup (timeptr->element);
                        ^
make[1]: *** [slinktool.o] Error 1
make[1]: Leaving directory `/home/davis/src/IGPP/slinktool/src'
make: *** [all] Error 2

If I follow @DonRhodes suggestion of tweaking the ezxml Makefile only, everything compiles.

davis@anfdevl ~/src/IGPP/slinktool (master *)$ git diff
diff --git a/ezxml/Makefile b/ezxml/Makefile
index fdfdf2d..d7f314f 100644
--- a/ezxml/Makefile
+++ b/ezxml/Makefile
@@ -3,6 +3,7 @@
 # environment variables:
 #   CC : Specify the C compiler to use
 #   CFLAGS : Specify compiler options to use
+CFLAGS = -std=c99

 LIB_OBJS = ezxml.o

Complile log:

Running make clean in libslink
make[1]: Entering directory `/home/davis/src/IGPP/slinktool/libslink'
rm -f gswap.o unpack.o msrecord.o genutils.o strutils.o logging.o network.o statefile.o config.o globmatch.o slplatform.o slutils.o gswap.lo unpack.lo msrecord.lo genutils.lo strutils.lo logging.lo network.lo statefile.lo config.lo globmatch.lo slplatform.lo slutils.lo libslink.a libslink.so.2.6 libslink.so.2 \
      libslink.so libslink.2.6.dylib libslink.dylib
make[1]: Leaving directory `/home/davis/src/IGPP/slinktool/libslink'
Running make clean in ezxml
make[1]: Entering directory `/home/davis/src/IGPP/slinktool/ezxml'
rm -f ezxml.o libezxml.a
make[1]: Leaving directory `/home/davis/src/IGPP/slinktool/ezxml'
Running make clean in src
make[1]: Entering directory `/home/davis/src/IGPP/slinktool/src'
rm -f dsarchive.o archive.o slinkxml.o slinktool.o ../slinktool
make[1]: Leaving directory `/home/davis/src/IGPP/slinktool/src'
davis@anfdevl ~/src/IGPP/slinktool (master *)$ make
Running make all in libslink
make[1]: Entering directory `/home/davis/src/IGPP/slinktool/libslink'
cc  -c gswap.c -o gswap.o
cc  -c unpack.c -o unpack.o
cc  -c msrecord.c -o msrecord.o
cc  -c genutils.c -o genutils.o
cc  -c strutils.c -o strutils.o
cc  -c logging.c -o logging.o
cc  -c network.c -o network.o
cc  -c statefile.c -o statefile.o
cc  -c config.c -o config.o
cc  -c globmatch.c -o globmatch.o
cc  -c slplatform.c -o slplatform.o
cc  -c slutils.c -o slutils.o
rm -f libslink.a
ar -crs libslink.a gswap.o unpack.o msrecord.o genutils.o strutils.o logging.o network.o statefile.o config.o globmatch.o slplatform.o slutils.o
make[1]: Leaving directory `/home/davis/src/IGPP/slinktool/libslink'
Running make all in ezxml
make[1]: Entering directory `/home/davis/src/IGPP/slinktool/ezxml'
cc -std=c99 -c ezxml.c
rm -f libezxml.a
ar -csq libezxml.a ezxml.o
make[1]: Leaving directory `/home/davis/src/IGPP/slinktool/ezxml'
Running make all in src
make[1]: Entering directory `/home/davis/src/IGPP/slinktool/src'
cc -I../libslink -I../ezxml -c dsarchive.c -o dsarchive.o
cc -I../libslink -I../ezxml -c archive.c -o archive.o
cc -I../libslink -I../ezxml -c slinkxml.c -o slinkxml.o
cc -I../libslink -I../ezxml -c slinktool.c -o slinktool.o
cc -o ../slinktool dsarchive.o archive.o slinkxml.o slinktool.o -L../libslink -L../ezxml -lslink -lezxml
make[1]: Leaving directory `/home/davis/src/IGPP/slinktool/src'

This results in a working executable:

davis@anfdevl ~/src/IGPP/slinktool (master *)$ ./slinktool
No SeedLink server specified

slinktool version 4.3

Usage: slinktool [options] [host][:][port]

Try '-h' for detailed help
geoffdavis commented 5 years ago

To spam this thread more, -std=c99 doesn't work as shown in previous comments, but -std=gnu99 results in a working executable.

Command used: CFLAGS=-std=gnu99 make

Log:

davis@anfdevl ~/src/IGPP/slinktool (master)$ CFLAGS=-std=gnu99 make
Running make all in libslink
make[1]: Entering directory `/home/davis/src/IGPP/slinktool/libslink'
cc -std=gnu99 -c gswap.c -o gswap.o
cc -std=gnu99 -c unpack.c -o unpack.o
cc -std=gnu99 -c msrecord.c -o msrecord.o
cc -std=gnu99 -c genutils.c -o genutils.o
cc -std=gnu99 -c strutils.c -o strutils.o
cc -std=gnu99 -c logging.c -o logging.o
cc -std=gnu99 -c network.c -o network.o
cc -std=gnu99 -c statefile.c -o statefile.o
cc -std=gnu99 -c config.c -o config.o
cc -std=gnu99 -c globmatch.c -o globmatch.o
cc -std=gnu99 -c slplatform.c -o slplatform.o
cc -std=gnu99 -c slutils.c -o slutils.o
rm -f libslink.a
ar -crs libslink.a gswap.o unpack.o msrecord.o genutils.o strutils.o logging.o network.o statefile.o config.o globmatch.o slplatform.o slutils.o
make[1]: Leaving directory `/home/davis/src/IGPP/slinktool/libslink'
Running make all in ezxml
make[1]: Entering directory `/home/davis/src/IGPP/slinktool/ezxml'
cc -std=gnu99 -c ezxml.c
rm -f libezxml.a
ar -csq libezxml.a ezxml.o
make[1]: Leaving directory `/home/davis/src/IGPP/slinktool/ezxml'
Running make all in src
make[1]: Entering directory `/home/davis/src/IGPP/slinktool/src'
cc -std=gnu99 -I../libslink -I../ezxml -c dsarchive.c -o dsarchive.o
cc -std=gnu99 -I../libslink -I../ezxml -c archive.c -o archive.o
cc -std=gnu99 -I../libslink -I../ezxml -c slinkxml.c -o slinkxml.o
cc -std=gnu99 -I../libslink -I../ezxml -c slinktool.c -o slinktool.o
cc -o ../slinktool dsarchive.o archive.o slinkxml.o slinktool.o -L../libslink -L../ezxml -lslink -lezxml
make[1]: Leaving directory `/home/davis/src/IGPP/slinktool/src'
davis@anfdevl ~/src/IGPP/slinktool (master)$ ./slinktool
No SeedLink server specified

slinktool version 4.3

Usage: slinktool [options] [host][:][port]

Try '-h' for detailed help
jschaeff commented 4 years ago

This is still the case for the newest release v4.3

chad-earthscope commented 4 years ago

I'm working on an update to libslink, an embedded dependency of this project. When the next release of libslink is ready, this tool will get updated and these small compiler warnings will be cleaned up.

Yaoshangheng commented 4 years ago

I had got the same issue on Centos7 with command "make",however I took @geoffdavis command "CFLAGS=-std=gnu99 make".It works!Thanks

chad-earthscope commented 1 year ago

The 4.x branch has fixes for all of the compiler errors that I could find. As soon as have confidence in this new branch I'll create a release. Testing and feedback is very welcome.

jschaeff commented 1 year ago

Is the 4.x branch for the version 4 of the protocol ? If it's compatible with version 3 of the seedlink protocol, I would be happy to give it a try.

chad-earthscope commented 1 year ago

The 4.x branch is the legacy branch that supports protocol <= 3. The previous release of 4.3 was created 7 years ago. Confusing I know but can't go backwards in versions. If a new version of SeedLink is approved it will be supported in a major new release (i.e. v5) of this program.

v4.4 was created: https://github.com/EarthScope/slinktool/releases/tag/v4.4 testing would be appreciated regardless.

jschaeff commented 1 year ago

Compilation and installation works flowlessly in Debian 11

I think this issue can be closed.