title: Cannot compile protoc-generated (C++) classes
body: <p>I'm currently having some troubles with compiling protobuf-generated C++ code.
  <code>protoc</code> runs correctly and doesn't show any warnings, however when I try to compile the generated C++ code so I can build a static library, g++ shows me the following message:</p>
  
  <blockquote>
    <p>CanInfo.pb.cc:107:5: error: ‘::protobuf_BusType_2eproto’ has not been declared
      107 |   ::protobuf_BusType_2eproto::AddDescriptors();</p>
  </blockquote>
  
  <p>What I've been able to gather so far, this is some issue with my BusType enumeration, which looks something like this:</p>
  
  <pre><code>syntax = "proto3";
  
  package MyPackage;
  
  enum BusType {
  
      ProprietaryBus = 0;
      OpenBus = 1;
      UnknownBus = 2;
  
  }
  </code></pre>
  
  <p>This enumeration is included by a message called CanInfo which looks something like this:</p>
  
  <pre><code>syntax = "proto3";
  
  package MyPackage;
  
  import "BusType.proto";
  
  message CanInfo {
  
      int32 interfaceId = 10;
      bool isConnected = 20;
      BusType busType = 30;
  
  }
  </code></pre>
  
  <p>As I mentioned before, <code>protoc</code> compiles these files "correctly" (without error).
  The version used to compile the protos is <strong>protoc 3.6.0</strong>.
  This is the portion of C++ code generated by <code>protoc</code>:</p>
  
  <pre><code>::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
        descriptor, 248);
  ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
      "data_containers/device_data/CanInfo.proto", &amp;protobuf_RegisterTypes);
  ::protobuf_BusType_2eproto::AddDescriptors();
  //           ^ error occurs here
  </code></pre>
  
  <p>Searching through the code, the only mention of the <code>protobuf_BusType_2eproto</code> namespace is the line above. 
  The compiler version used to compile the C++ code is <code>powerpc-linux-gnu-g++-6 (Ubuntu 6.4.0-17ubuntu1) 6.4.0 20180424</code>.
  Changing the G++ version used to version 8 or 9 <strong>doesn't</strong> change this behaviour.</p>
  
  <p>I've tried cleaning the build directory many times, and I've tried switching to a different protobuf version (3.4.0), however this also resulted in many compiler errors, mostly because the <code>protoc</code> version was too old.</p>
  
  <p>Building each file individually also doesn't change the behaviour.</p>
  
  <p>What is causing this behaviour? I've not had issues using Protobuf until now.
  Has anyone experienced this before and knows a handy trick?</p>
  
  <hr>
  
  <p><strong>EDIT</strong>
  Could this possibly be caused by the way I'm calling <code>protoc</code>?</p>
  
  <pre><code>###
  # Re-compile protos
  ###
  set(BUILD_PROTOS True)
  set(PROTOBUF_COMPILER protoc)
  if (BUILD_PROTOS)
      function(BUILD_PROTOS)
          foreach(PROTO ${PROTOS})
              message("Compiling ${PROTO}...")
              execute_process(
                  COMMAND ${PROTOBUF_COMPILER} ${PROTO_DIRS} "--cpp_out=${CMAKE_CURRENT_BINARY_DIR}" ${PROTO}
                  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
              )
          endforeach()
      endfunction()
  
      ###
      # Compile all protos
      ###
      BUILD_PROTOS()
  endif()
  </code></pre>