Strange behavior of macro __FILE__


(Kurokawa Masato) #1

As you know, macro__FILE__ in c/c++ contain a path to file, from where it was compiled.
For example:

gcc test.c -o test
./test
test.c

gcc myFolder/test.c -o test
./test
myFolder/test.c

But when I try to compile with gradle, it output the full path to my file, like:

home/usr/myFolder/test.c.

I want to precompile macro__FILE__ contain only interior project path but not full.

Gradle File:

apply plugin: 'c'

model {
    components {
            main(NativeExecutableSpec) {
                    sources {
                        c {
                            source {
                                srcDir "./"
                                include "*.c"
                            }
                        }
                    }
            }
    }
}

test.c:

#include <stdio.h>

void main(void)
{
    printf("%s\n", __FILE__);
}