Use batch processing to add a pre-compiled header to the output c ++ file of protocbuffer

Source: Internet
Author: User

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.