-d_gnu_source


 
Thread Tools Search this Thread
Top Forums Programming -d_gnu_source
# 1  
Old 09-19-2008
-d_gnu_source

brothers

//open.c

#include<stdio.h>

#include<sys/types.h>
#include<dlfcn.h>

int open(char const *path,int mode,mode_t permission)
{
int (*point)(char const ,int ,mode_t)=NULL;
FILE *out;
int type;
char *actualpath,*lisaoutput;
lisaoutput=getenv("LISA_TRACE");
point= dlsym( RTLD_NEXT,"open" );
type=point(path,mode,permission);
if(type!=-1)
{
printf("%s\n",path);
}
}

i wrote this program .. when i tried to compile i got the following error

lohi@look:~/cl/lisa$ cc -c open.c -ld
open.c: In function ‘open':
open.c:12: warning: assignment makes pointer from integer without a cast
open.c:13: error: ‘RTLD_NEXT' undeclared (first use in this function)
open.c:13: error: (Each undeclared identifier is reported only once
open.c:13: error: for each function it appears in.)
open.c:14: warning: passing argument 1 of ‘point' makes integer from pointer without a cast

then i saw -D_GNU_SOURCE , -Fpic option used by some one .
i dont know why we use it ?


lohi@look:~/cl/lisa$ cc -c open.c -D_GNU_SOURCE -fPIC -ld
open.c: In function ‘open':
open.c:12: warning: assignment makes pointer from integer without a cast
open.c:14: warning: passing argument 1 of ‘point' makes integer from pointer without a cast
gcc.real: -ld: linker input file unused because linking not done

please help me telling why we use it..
searching in google . im not getting an appropriate explanation .

please explain D_GNU_SOURCE option and -fpic option

lohi@look:~/cl/lisa$ gcc -D_GNU_SOURCE -fPIC -c open.c
open.c: In function ‘open':
open.c:12: warning: assignment makes pointer from integer without a cast
open.c:14: warning: passing argument 1 of ‘point' makes integer from pointer without a cast
lohi@look:~/cl/lisa$
# 2  
Old 09-20-2008
please reply
# 3  
Old 02-05-2009
If the code depends on GNU functions, then we'll get warnings and fix
it once -D_GNU_SOURCE is removed.

If the code depends on incorrect GNU semantics in standardized
functions (which conflict with POSIX) then the code is already
_BROKEN_ on non-GNU implementations, and -D_GNU_SOURCE just works
around the problem on GNU systems. If this is the case it's better to
let it break then find the problems and fix it rather than having
subtle bugs. But I doubt it's the case anyway.

Either way, using -D_GNU_SOURCE is a very bad idea IMO.

If you're worried about differing from upstream we should complain to
upstream and ask them to remove the -D_GNU_SOURCE.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question