Sunday 14 April 2019

c++ - MSVC /FA GCC equivalent




I'm using GCC to compiler and I want to print the full path of the file using __FILE__, but GCC shows only the name of the file. In MSVC is the same, but you can use an argument /FC (Full Path of Source Code File in Diagnostics) and it works. Is there any equivalent to GCC?



int main(int argc, char ** argv)
{
std::cout << __FILE__ << std::endl;
return 0;
}

Answer




I couldn't find any equivalent, but I realized that __FILE__ macro expands to the name of the current input file via the path used by the preprocessor to open the file. So it will depend on what is passed to the compiler.



I solved it using CMake as build system. When CMake creates the MakeFile it uses the full path in the variable CMAKE_SOURCE_DIR, this way __FILE__ will print exactly what we expect.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...