2013年3月22日 星期五

have error when build mini_httpd : previous declaration of ‘getline’ was here

mini_httpd官網

編譯mini_httpd

  1. wget http://www.acme.com/software/mini_httpd/mini_httpd-1.19.tar.gz
  2. tar zxvf mini_httpd-1.19.tar.gz
  3. cd mini_httpd-1.19/
  4. make
出現錯誤
htpasswd.c:52: error: conflicting types for ‘getline’
/usr/include/stdio.h:651: note: previous declaration of ‘getline’ was here
htpasswd.c: In function ‘add_password’:
htpasswd.c:117: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result
htpasswd.c: In function ‘main’:
htpasswd.c:216: warning: ignoring return value of ‘system’, declared with attribute warn_unused_result
make: *** [htpasswd.o] Error 1

htpasswd.c第52行所宣告的名字getline與/usr/include/stdio.h +651命名相同
以下是/usr/include/stdio.h部分內容
/* Like `getdelim', but reads up to a newline.

   This function is not part of POSIX and therefore no official
   cancellation point.  But due to similarity with an POSIX interface
   or due to the implementation it is a cancellation point and
   therefore not marked with __THROW.  */
extern _IO_ssize_t getline (char **__restrict __lineptr,
                size_t *__restrict __n,
                FILE *__restrict __stream) __wur;
#endif

修改方式將htpasswd.c第52行函數命名方式修改 from getline to getlinexxx
另外第192行也需要修改

重新編譯
make clean
make
OK

最後訊息
gcc -O   -c match.c
gcc -O   -c tdate_parse.c
gcc -O   -s mini_httpd.o match.o tdate_parse.o   -lcrypt -o mini_httpd
gcc -O   -c htpasswd.c
htpasswd.c: In function ‘add_password’:
htpasswd.c:117: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result
htpasswd.c: In function ‘main’:
htpasswd.c:216: warning: ignoring return value of ‘system’, declared with attribute warn_unused_result
gcc -O   -s htpasswd.o -lcrypt -o htpasswd




透過Facebook分享

沒有留言: