LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   compiling problem? (https://www.linuxquestions.org/questions/programming-9/compiling-problem-476645/)

kalleanka 08-23-2006 01:02 PM

compiling problem?
 
i have this example.

#include <unistd.h>
int main()
{
usleep(1000);
return 0;
}


that compiles fine with gcc -Wall test.c -o test

but with:
gcc -c -Wall -O2 -g -O2 -ansi -I/usr/X11R6/include -I/usr/include/freetype2 -I/usr/include/freetype2/config -I/usr/X11R6/include -I/usr/X11R6/include -I/usr/include/gtk-2.0 -I/usr/include `pkg-config gtk+-2.0 --cflags --libs` test.c

I get test.c:4: warning: implicit declaration of function ‘usleep’

and no warning eliminating -ansi


so do I have any danger ignoring the warning or shall I skipp -ansi?

xhi 08-23-2006 01:13 PM

> and no warning eliminating -ansi

is usleep standard?

kalleanka 08-23-2006 02:29 PM

I guess not.

from man 3 usleep


SYNOPSIS
/* BSD version */
#include <unistd.h>

void usleep(unsigned long usec);

/* SUSv2 version */
#define _XOPEN_SOURCE 500
#include <unistd.h>

int usleep(useconds_t usec);

kalleanka 08-23-2006 02:33 PM

maybe I should use nanosleep instead from time.h

kalleanka 08-23-2006 02:57 PM

sorry I saw now in the man page: This function is obsolete. Use nanosleep(2) or setitimer(2) instead.

so I go for nanosleep.

whk 08-24-2006 01:58 AM

Just a caution - the use of 'test' as a name for the compiled program conflicts with bash.

Also you can use -Wall in g++

xhi 08-24-2006 07:47 AM

Quote:

Originally Posted by whk
Just a caution - the use of 'test' as a name for the compiled program conflicts with bash.

Also you can use -Wall in g++

as long as you specify the absolute path to your test executable (./test) you should be fine.

i would also agree that -Wall is a good habit to get into

kalleanka 08-26-2006 07:45 AM

ok I shall use another name then test in the future even if I have a absolute path. One day I will not an get in to trouble.

Thanks.


All times are GMT -5. The time now is 01:15 AM.