title: cross compile protobuf files in cmake with Yocto sdk
body: <p>I am trying to compile <a href="https://github.com/googlecartographer/cartographer/blob/master/CMakeLists.txt" rel="nofollow noreferrer">cartographer</a> in a Docker container with an SDK generated with Yocto.</p>
  
  <p>The SDK is running well since I can cross compile what I want on it, except cartographer.</p>
  
  <p>The issue I have is the CMakeLists.txt calls <code>protoc</code>( from <a href="https://github.com/google/protobuf" rel="nofollow noreferrer">protobuf</a>). I have protoc installed in the host and target directory.</p>
  
  <pre><code>add_custom_command(
    OUTPUT "${PROJECT_BINARY_DIR}/${DIR}/${FIL_WE}.pb.cc"
           "${PROJECT_BINARY_DIR}/${DIR}/${FIL_WE}.pb.h"
    COMMAND  ${PROTOBUF_PROTOC_EXECUTABLE}
    ARGS --cpp_out  ${PROJECT_BINARY_DIR} -I
      ${PROJECT_SOURCE_DIR} ${ABS_FIL}
    DEPENDS ${ABS_FIL}
    COMMENT "Running C++ protocol buffer compiler on ${ABS_FIL}"
    VERBATIM
  )
  </code></pre>
  
  <p>I'm a bit confused because while having protoc already available, I'm calling protoc with an x86_64 architecture while I am using an <code>aarch64-poky-linux-</code> compiler. This leads to libraries not found, since architectures are somehow mixed up. glog is also installed on both architectures:</p>
  
  <pre><code>make[2]: *** No rule to make target '/home/yocto/yocto_topdir/tmp/sysroots/raspberrypi-cm3-64/usr/lib/libglog.so', needed by 'cartographer/kalman_filter/kalman_filter_unscented_kalman_filter_test'.  Stop.
  make[2]: *** Waiting for unfinished jobs....
  make[2]: *** No rule to make target '/home/yocto/yocto_topdir/tmp/sysroots/raspberrypi-cm3-64/usr/lib/libglog.so', needed by 'cartographer/kalman_filter/kalman_filter_gaussian_distribution_test'.  Stop.
  make[2]: *** Waiting for unfinished jobs....
  make[2]: *** No rule to make target '/home/yocto/yocto_topdir/tmp/sysroots/raspberrypi-cm3-64/usr/lib/libglog.so', needed by 'cartographer/common/common_fixed_ratio_sampler_test'.  Stop.
  make[2]: *** Waiting for unfinished jobs....
  make[2]: *** No rule to make target '/home/yocto/yocto_topdir/tmp/sysroots/raspberrypi-cm3-64/usr/lib/libglog.so', needed by 'cartographer/common/common_lua_parameter_dictionary_test'.  Stop.
  make[2]: *** Waiting for unfinished jobs....
  make[2]: *** No rule to make target '/home/yocto/yocto_topdir/tmp/sysroots/raspberrypi-cm3-64/usr/lib/libglog.so', needed by 'cartographer/common/common_blocking_queue_test'.  Stop.
  make[2]: *** Waiting for unfinished jobs....
  make[2]: *** No rule to make target '/home/yocto/yocto_topdir/tmp/sysroots/raspberrypi-cm3-64/usr/lib/libglog.so', needed by 'cartographer/mapping/mapping_probability_values_test'.  Stop.
  make[2]: *** Waiting for unfinished jobs....
  make[2]: *** No rule to make target '/home/yocto/yocto_topdir/tmp/sysroots/raspberrypi-cm3-64/usr/lib/libglog.so', needed by 'cartographer/common/common_math_test'.  Stop.
  make[2]: *** Waiting for unfinished jobs....
  make[2]: *** No rule to make target '/home/yocto/yocto_topdir/tmp/sysroots/raspberrypi-cm3-64/usr/lib/libglog.so', needed by 'cartographer/common/common_rate_timer_test'.  Stop.
  make[2]: *** Waiting for unfinished jobs....
  make[2]: *** No rule to make target '/home/yocto/yocto_topdir/tmp/sysroots/raspberrypi-cm3-64/usr/lib/libglog.so', needed by 'cartographer/mapping_2d/mapping_2d_probability_grid_test'.  Stop.
  make[2]: *** Waiting for unfinished jobs....
  make[2]: *** No rule to make target '/home/yocto/yocto_topdir/tmp/sysroots/raspberrypi-cm3-64/usr/lib/libglog.so', needed by 'cartographer/mapping/mapping_trajectory_connectivity_test'.  Stop.
  make[2]: *** Waiting for unfinished jobs....
  make[2]: *** No rule to make target '/home/yocto/yocto_topdir/tmp/sysroots/raspberrypi-cm3-64/usr/lib/libglog.so', needed by 'cartographer/mapping/mapping_submaps_test'.  Stop.
  make[2]: *** Waiting for unfinished jobs....
  make[2]: *** No rule to make target '/home/yocto/yocto_topdir/tmp/sysroots/raspberrypi-cm3-64/usr/lib/libglog.so', needed by 'cartographer/kalman_filter/kalman_filter_pose_tracker_test'.  Stop.
  make[2]: *** Waiting for unfinished jobs....
  </code></pre>
  
  <p>One strange thing is the mentioned directory (/home/yocto/yocto_topdir/tmp/sysroots/raspberrypi-cm3-64) only exists in the Yocto workspace when generating the SDK. It is not a CMAKE variable from what I checked but it comes from somewhere else.</p>
  
  <p>Simply doing in my container solved the issue</p>
  
  <pre><code>mkdir -p /home/yocto/yocto_topdir/tmp/sysroots
  ln -s /usr/local/oecore-sdk/sysroots/aarch64-poky-linux /home/yocto/yocto_topdir/tmp/sysroots/raspberrypi-cm3-64 
  </code></pre>
  
  <p>I don't write it as an answer since it's a 'hack'. It simply points to the folder container the sysroot of the target</p>
  
  <p>EDIT: Added more details</p>