pesco / dnp3

A DNP3 parser implementation in Hammer
15 stars 7 forks source link

dissect executable doesn't build on Ubuntu w/ gcc 4.8.4 #8

Closed jadamcrain closed 8 years ago

jadamcrain commented 8 years ago

Compiler error is:

[ 71%] Building C object CMakeFiles/dissect.dir/dissect.c.o
/home/user/dev/hammer-dnp3/dissect.c: In function ‘main’:
/home/user/dev/hammer-dnp3/dissect.c:131:5: warning: implicit declaration of function ‘getopt’ [-Wimplicit-function-declaration]
     while((ch = getopt(argc, argv, "TAfh")) != -1) {
     ^
/home/user/dev/hammer-dnp3/dissect.c:151:13: error: ‘optind’ undeclared (first use in this function)
     argc -= optind;

Appears to be choking on missing definitions for getopt & optind from .

Not sure if I am missing something or if getopt.h isn't commonly supported.

going through unistd.h, it appears that __USE_POSIX2 isn't defined on my system:

#ifdef  __USE_POSIX2
/* Get definitions and prototypes for functions to process the
   arguments in ARGV (ARGC of them, minus the program name) for
   options given in OPTS.  */
# define __need_getopt
# include <getopt.h>
#endif

Any ideas?

pesco commented 8 years ago

Oh, it seems glibc hides getopt with -std=c99 because apparently, when in doubt, POSIX features have no place in unistd.h.

Compile with CFLAGS="-D_POSIX_C_SOURCE=2". I'll add this to the cmake file.

pesco commented 8 years ago

fc2f3a0 should fix this.