You can use the ProtocolBuffer compiler protoc. proto generation *. pb. cc C ++ code file. however, in projects with pre-compiled headers, you often need to manually add stdafx-like files. h. here we use batch processing to complete this process:
BuildProtoCC. bat
@ Echo off
Set protofile = % 1%. proto
Set output_cc = % 1%. pb. cc
"Protoc.exe" % protofile % -- cpp_out.
@ Echo use % protofile % to generate % output_cc %
If exist "pchheader.txt" goto merge precompiled headers else echo pchheader.txt NOT EXIST
: Merge pre-compiled Headers
@ Echo try to delete the previous intermediate file
Del *. pched
@ Echo merge the compilation and translation header file pchheader.txt to generate % output_cc %
Copy pchheader.txt + "% output_cc %" "% output_cc %. pched"/y
@ Echo wait until protoc.exe ends
@ Ping-n 2 127.1> nul
Echo file cleanup
Del "% output_cc %"
Ren "% output_cc %. pched" "% output_cc %"
This batch is used as follows:
Suppose you have a file named login. proto put together with the batch processing.
Put a pchheader.txt file in the same directory, and write # include "stdafx. h"
Call Batch Processing
Call BuildProtoCC. bat login
Note that login cannot contain a suffix.
Use protoc.exe to generate login. pb. cc and login. pb. h, and then use the batch file merging function to automatically merge pre-compilation headers.
Excerpted from: war spirit Xiaozhu