Ok, I understood a little. But I still have doubts on how to use it. I tried to declare a variable receiving GCOV_IP_ADDRESS within gcov-io.c # if IN_LIBGCOV const char * gcov_ip_address = GCOV_IP_ADDRESS; # endif but, as I imagined, the build failed. ../../../gcc-4.6.0/libgcc/../gcc/gcov-io.c: 38:31: error: 'GCOV_IP_ADDRESS' undeclared here (not in a function) I need to declare GCOV_IP_ADRESS in any place? Thanks for the help 2011/8/9 Andi Hellmund <andi@xxxxxxxxxxxxxx>: > Hi Harry, >> >> I think this option (-D) can be useful. But I did not understand how >> to use this option . >> > > The -D options defines a C macro via the command-line. It's equivalent to > using #define MACRO in your source code. >> >> You told me to create a new file, but this file is for the GCC or for >> the program being compiled? >> > > This file is then used for the program being compiled, not for GCC. >> >> Using the -D option, I can access the IP address within the compiled >> program or just during compilation? >> > > Only within the compiled program, but that's where libgcov is running so > that's the place where the IP address is needed ... > > Best regards, > Andi > > > >> 2011/8/5 Ian Lance Taylor<iant@xxxxxxxxxx>: >> >>> >>> Harry Trinta<harrytpc@xxxxxxxxx> writes: >>> >>> >>>> >>>> I'm developing a mechanism in the gcov, instead of writing the file >>>> gcda (in file gcov-io.c), it sends the information to a host via a >>>> socket. The host generates gcda. >>>> >>>> So I'd like to get the IP at compile time to use when sending the data >>>> through the socket. >>>> >>>> But from what you said, the variable is only available at compile >>>> time, which is not my case. >>>> >>>> >>>>> >>>>> To be clear, this will give you a new variable in the compiler itself. >>>>> It will not give you a variable in the gcov program, nor in the program >>>>> you are compiling. You will have to figure out some mechanism to get >>>>> the value to the point where you need it. It's not clear to me where >>>>> that point is. >>>>> >>>> >>>> What kinds of mechanisms I can develop to use this variable when >>>> sending information? >>>> >>> >>> There are many ways to get an IP address defined at compile time into >>> the gcov library. Most of them do not involve changing the compiler >>> proper at all (you do of course have to change the gcov support >>> library). >>> >>> Making this a compile time option seems odd. What should happen if you >>> link together two different files compiled with different values for the >>> option? What you really want is to make a link time option. >>> >>> Suppose you just change the gcov library to look for a global variable >>> gcov_ip_address. Then create a tiny file >>> >>> const char* gcov_ip_address = GCOV_IP_ADDRESS >>> >>> Then compile that file with -DGCOV_IP_ADDRESS=nn.nn.nn.nn. >>> >>> That approach is much simpler than changing the compiler proper. What >>> do you need that you can't get from that? >>> >>> Ian >>> >>> > >