title: Undefined symbol when loading a shared library
body: <p>In my program I need to load a shared library dynamically with <code>dlopen()</code>. Both the program and the shared library are successfully cross-compiled for an <code>ARM</code> architecture with the cross-compiler installed on my <code>x86</code>. However, whenever the program tries to load the library at run time on <code>ARM</code>, it fails giving this error: </p>
  
  <blockquote>
    <p>undefined symbol: _dl_hwcap</p>
  </blockquote>
  
  <p>I cannot find the culprit of this error.</p>
  
  <p>Let me give details on how the shared library (<code>libmyplugin.so</code>) is built on <code>x86</code> first. I use the <code>g++</code> cross-compiler as below:</p>
  
  <pre><code>/home/me/arm/gcc-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ -march=armv7-a -mfloat-abi=hard -c -s -fPIC -o build/module1.o module1.cpp
  /home/me/arm/gcc-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ -march=armv7-a -mfloat-abi=hard -c -s -fPIC -o build/module2.o module2.cpp
  /home/me/arm/gcc-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ -o dist/libmyplugin.so build/module1.o build/module2.o --sysroot /home/me/arm/sysroot/ -Wl,--no-as-needed -ldl -lX11 -lXext /home/me/arm/libstatic.a -shared -s -fPIC
  </code></pre>
  
  <p>Please pay attention to the following notes:</p>
  
  <ol>
  <li><code>module1.cpp</code> and <code>module2.cpp</code> are my source code files.</li>
  <li><code>libstatic.a</code> is a big archive of object <code>.o</code> files implementing the stuff directly invoked/referenced by <code>module1.cpp</code> and <code>module2.cpp</code>. These object files have been compiled by others for the same ARM architecture as mine, with the same compiler flags, but using a slightly more updated <code>g++</code> compiler (<code>v4.9</code> instead of my <code>v4.8.3</code>). Unfortunately, I have no control on the building of these objects.</li>
  <li><code>--sysroot /home/me/arm/sysroot/</code> represents the remote filesystem of my <code>ARM OS</code> from which the local <code>g++</code> cross-compiler can take the native libraries while linking.</li>
  <li><code>-Wl,--no-as-needed -ldl -lX11 -lXext</code>: these flags are required to force the dynamic loader to load the <code>X11</code> libraries present on the system when my shared library is loaded by the program. In particular, <code>--no-as-needed</code> is required because the <code>X11</code> libraries are NOT directly referenced by <code>module1.o</code> and <code>module2.o</code>; on the contrary the <code>X11</code> libraries are referenced by the static library only.</li>
  </ol>
  
  <p>Note that all the above setup works on <code>x86</code>. It's just that I don't understand what is the reason of the <code>_dl_hwcap</code> symbol not resolved when the program tried to load the library on <code>ARM</code>.</p>
  
  <p>Do you have any idea how to investigate this issue?</p>