How can I save Clang diagnostics to a file?

I write a web server, mainly for practice, and decided to get acquainted with make and make files. My goal is to automate the assembly of my vps using Clang / LLVM to create software and save the diagnostics in a text file so that the script can send to my email address. What I cannot achieve is to save the diagnostics in my file.

While my Clang is working successfully and generating diagnostics, and my makefile seems to be working, I was unable to redirect the diagnostics both inside the makefile and from the command line.

My makefile (works correctly, but slightly modified to save the need to save results):

# Makefile to build Ironman HTTP Server # We will use the clang frontend from the llvm compiler infrastructure # for building # --- targets Ironman : clang -o Ironman src/Ironman.c > report # --- remove binary and executable files clean: rm -f Ironman rm -f report 

I suspect that (maybe I'm terribly mistaken here) this is because clang doesn't really return diagnostics, it just prints them. I don't know if this is the case, and the Clang user guide does not offer anything like this.

[EDIT]: I played a little with Clang and saw that, on successful compilation, it returns 0. The method with which I tested it is:

 $ clang <source_file.c> $ echo $? 0 

This suggests that my theory may be correct, which complicates things: - \

Can someone point me in the right direction?

+4
source share
1 answer

Clang, like any other program, displays diagnostics on stderr. You can redirect stderr to stdout as follows:

 Ironman : clang -o Ironman src/Ironman.c > report 2>&1 
+5
source

All Articles