title: Executable says "line 1: ELF: not found" when starts
body: <p>I try to build a simple <strong>hello, world</strong> <code>ELF</code> for my router <code>Xiaomi Router 3g</code> with <code>cmake</code>. It runs </p>
  
  <pre><code>Linux OpenWrt 4.14.95 #0 SMP Wed Jan 30 12:21:02 2019 mips GNU/Linux
  </code></pre>
  
  <p>I use <a href="https://downloads.openwrt.org/snapshots/targets/ramips/mt7621/openwrt-sdk-ramips-mt7621_gcc-7.4.0_musl.Linux-x86_64.tar.xz" rel="nofollow noreferrer">the sdk for ramips platform (my router's platform)</a>.</p>
  
  <p>The idea is to use <code>$(PKG_BUILD_DIR)</code> as a directory to perform an external build (which is usually done via <code>mkdir build ; cd build ; cmake ..</code>)</p>
  
  <p>The build finishes successfully and when I install it on my router and start it, it fails with:</p>
  
  <pre class="lang-sh prettyprint-override"><code>root@OpenWrt:~# chw
  /usr/bin/chw: line 1: ELF: not found
  /usr/bin/chw: line 2: syntax error: unexpected "("
  </code></pre>
  
  <p>When I build the <code>ELF</code> without <code>cmake</code> (</p>
  
  <ol>
  <li>comment out the line <code>include $(INCLUDE_DIR)/cmake.mk</code>,</li>
  <li>uncomment the  <code>$(CP) ...</code> line in the <code>define Build/Prepare</code> section</li>
  <li>eliminate the <code>define Build/Compile</code> section</li>
  </ol>
  
  <p>), it works just fine: it prints <strong>Hello, World!</strong>.</p>
  
  <p>Log file is <a href="https://gist.github.com/neshkeev/28f3828688fe354e7358bc9b1fbbe9a5" rel="nofollow noreferrer">here</a>, 
  <code>.config</code> file is <a href="https://gist.github.com/neshkeev/02da79c8d39226d233f5d05dc13833a0" rel="nofollow noreferrer">here</a> </p>
  
  <p><strong>The source code is available</strong> <a href="https://github.com/neshkeev/openwrt-cmake-demo" rel="nofollow noreferrer">here</a></p>
  
  <p>Here is the source code:</p>
  
  <p><code>main.c</code>:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      printf("Hello, World!");
      return 0;
  }
  
  </code></pre>
  
  <p><code>CMakeLists.txt</code>:</p>
  
  <pre><code>cmake_minimum_required (VERSION 2.6)
  
  project (chw)
  
  add_executable(chw main.c)
  
  install(TARGETS chw DESTINATION /usr/bin)
  </code></pre>
  
  <p><code>Makefile</code>:</p>
  
  <pre><code>include $(TOPDIR)/rules.mk
  
  PKG_NAME:=chw
  PKG_VERSION:=0.1
  PKG_RELEASE:=1
  
  PKG_MAINTAINER:=John Doe &lt;john.doe@example.com&gt;
  PKG_LICENSE:=CC0-1.0
  
  include $(INCLUDE_DIR)/package.mk
  include $(INCLUDE_DIR)/cmake.mk
  
  define Package/chw
      SECTION:=utils
      CATEGORY:=Utilities
      TITLE:=Hello world application
      URL:=https://www.example.com
  endef
  
  define Package/chw/description
      hello world application
  endef
  
  define Build/Prepare
      mkdir -p $(PKG_BUILD_DIR)
      # $(CP) ./src/{main.c,Makefile} $(PKG_BUILD_DIR)/
  endef
  
  define Build/Configure
      cmake -B $(PKG_BUILD_DIR) -S ./src
  endef
  
  define Build/Compile
      $(call Build/Compile/Default,-C $(PKG_BUILD_DIR))
  endef
  
  define Package/chw/install
      $(INSTALL_DIR) $(1)/usr/bin
      $(INSTALL_BIN) $(PKG_BUILD_DIR)/chw $(1)/usr/bin/
  endef
  
  $(eval $(call BuildPackage,chw))
  </code></pre>