LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-03-2011, 12:52 PM   #1
hajiman
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Rep: Reputation: Disabled
how to address warnings?


I use gcc to compile a .c file and get the following warnings when I execute the make file:

gcc -c -std=c99 gps2.c
gps2.c: In function 'run_gps2':
gps2.c:253:5: warning: implicit declaration of function 'localtime_r'
gps2.c:257:5: warning: implicit declaration of function 'asctime_r'
gps2.c:274:13: warning: implicit declaration of function 'strerror_r'
gps2.c:348:21: warning: implicit declaration of function 'timersub'
gps2.c: In function 'get_GPRMC_record':
gps2.c:1397:17: warning: implicit declaration of function 'strsep'

I have the following includes at the top of gps2.c:
#include <string.h>
#include <time.h>

How do I address these warning?

When I compile with g++, I don't get these warnings, however, I need to use gcc, not g++:
e.g. g++ -c gps2.c

Thanks much!
 
Old 08-03-2011, 01:39 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Code:
// PROBLEM:
gps2.c:253:5: warning: implicit declaration of function 'localtime_r'
gps2.c:257:5: warning: implicit declaration of function 'asctime_r'
gps2.c:274:13: warning: implicit declaration of function 'strerror_r'
...
Code:
// SOLUTION:
#include <time.h>
#include <string.h>
Except that you already ARE #includ'ing the necessary headers

SUGGESTION:
Look at /usr/include/string.h (for example):
Code:
#if defined __USE_XOPEN2K || defined __USE_MISC
/* Reentrant version of `strerror'.
   There are 2 flavors of `strerror_r', GNU which returns the string
   and may or may not use the supplied temporary buffer and POSIX one
   which fills the string into the buffer.
   To use the POSIX version, -D_XOPEN_SOURCE=600 or -D_POSIX_C_SOURCE=200112L
   without -D_GNU_SOURCE is needed, otherwise the GNU version is
   preferred.  */
   ...
SUGGESTIONS:
1. Try compiling *without* the "c99" (if possible)
2. Try different combinations of "-D"
 
Old 08-03-2011, 04:18 PM   #3
hajiman
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
> 1. Try compiling *without* the "c99" (if possible)

The problem goes away when the c99 option is not used. I used that option because it allows me to declare a variable in a for loop statement.
for (int i = 0; i < x; i++)
I've changed my code so that I can live without the c99 option. The warnings are rather quirky if the c99 option causes them.

Thanks for your suggestions.
 
  


Reply

Tags
compiler, gcc, warning


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Warnings on installation ssaha Solaris / OpenSolaris 0 07-21-2010 01:54 AM
Pointer warnings rubadub Programming 17 08-08-2007 01:26 PM
c warnings kpachopoulos Programming 1 08-25-2006 06:45 AM
Warnings from make Conjurer Linux - Software 1 11-12-2005 02:10 AM
how to get ip address, broadcast address, mac address of a machine sumeshstar Programming 2 03-12-2005 04:33 AM


All times are GMT -5. The time now is 04:51 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration