Clang: make __FILE__ use absolute path?

When compiling with MSVC, the /FC flag can be used to make the __FILE__ macro resolve to the absolute path of the current source file.

Is anyone aware of a similar option for Clang? Currently, when building in Xcode __FILE__ resolves to a path that is relative to the .xcodeproj file. I’ve found the -fdiagnostics-absolute-paths flag that looked promising, but it seems to have no effect. AFAICT the only way to change this behavior is by using the absolute path for each source file that is passed to Clang. I’m working on a Projucer-based project, and I’m not aware of any practical way to change the source filepaths that are added to the generated Xcode project.

Maybe using -working-directory could work.

1 Like

Alright, that seems to be working!

I added -working-directory=$PROJECT_DIR to the Xcode compiler flags and now __FILE__ is working as expected, giving me the absolute path to the current source.

Thanks for the help @McMartin!

1 Like