Skip to content
bluehazzard edited this page Oct 2, 2018 · 1 revision

Using google protocol buffers within codeblocks

This guide shows you how to integrate the protocol buffer compiler within codeblocks so the .proto files get automatically generated and updated on build

Setup compiler

  1. Download the protocol buffer framework: Download and install the protobuffer compiler and library on your system
  2. Open Codeblocks
  3. Settings -> Compiler -> Global compiler settings
  4. Select your compiler from the Selected compiler list. (Normally you use the GNU GCC Compiler)
  5. Select the tab Toolchain executables and then Additional Paths
  6. Enter the path to the installed protoc executable (Where you have installed proto buffer) If the installation path is in the system PATH variable, or in the compiler path you do not have to do this.
  7. Hit the right arrow button under the "Reset default" button until Other settings tab appears and select it
  8. Click Advanced options
  9. Select tab Commands and from the "Command" dropdown select Compile single file to object file
  10. Next to the Source ext click the + button and enter proto
  11. In "Command line macro" enter
protoc -I $file_dir --cpp_out=$file_dir $file_name.$file_ext
  1. in "Generated files (to be future compiled):" enter
$file_dir/$file_name.pb.cc
$file_dir/$file_name.pb.h
  1. Hit Ok on all Dialogs to leave the settings

Setup global variables for easy use of include paths

If you use linux you probably can skip this, because the protobuffer library is installed on system level.

  1. Settings -> global variables
  2. New -> enter protobuffer
  3. Select protobuffer from the list
  4. Enter the path to your protobuffer base installation path in the basefield. You can use the ... button to browse
  5. Enter in the include field the path to the include sub folder of the protobuffer installation directory
  6. Enter in the lib field the path to the lib sub folder of the protobuffer installation directory
  7. Close the dialog

Setup the project to use with proto buffer

  1. Create a new project with File -> new project
  2. Set up the build options: Project -> Build options
  3. Select the project name from the tree control on the left
  4. Select the tab Linker settings -> Add -> enter the name of the protocolbuffer library libprotobuf
  5. Select the tab Search directories-> Compiler -> Add -> Push the button with right most button. This will open a dialog with the name Get global variable and select protobuffer -> include
  6. Select the tab Search directories-> Linker -> Add -> Push the button with right most button. This will open a dialog with the name Get global variable and select protobuffer -> lib
  7. 'Ok' to close all dialogs
  8. Add the .proto files to your project. Codeblocks will create a virtual Folder with the name Auto-generated with the corresponding names of the source files like the proto files
  9. You may have the problem that the source files that include the proto.h files are compiled before the protoc compiler is called. To fix this you have to elevate the protoc priority so the files are generated before other source files are build. To do this: Select the .proto file from the project tree and make right click -> properties -> Build -> Priority weight: 0 . This will ensure that the proto file is always build before the c files

Clone this wiki locally