title: How do I cross compile a static library built on the target with static linkage using c++11 utilities
body: <p>**Edit: Found my problem. As explained by the following answer, I was not actually doing any linking when making the static library. Instead, I made a shared library and linked libstdc++ statically.</p>
  
  <p><a href="https://stackoverflow.com/questions/46455558/compile-a-static-library-link-with-standard-library-static">Compile a static library link with standard library (static)</a>**</p>
  
  <p>I am trying to create a method to use c++11 on an ancient arm platform running kernel (2.6.37). Unfortunately the latest cross compile our BSP contains is GCC 4.5.3, which does not support all the c++11 utilites we need.</p>
  
  <p>Initially I tried to use old versions of crosstool-ng to build a cross compiler, but the older versions were too broken. The newer versions did not support the 2.6.37 kernel. I was able to complete one build, however the g++ binary was not built, making the whole endeavor useless (I did check that c++ was enabled in the menuconfig). </p>
  
  <p>Thus my last option was to build gcc natively at version 4.9.4 and create a statically linked library to have my gcc 4.5.3 cross compiler link against. This seems to work for the most part. I create my library on the target with the following:</p>
  
  <pre><code>g++ -std=c++11 --static -c main2.cpp
  ar -cvq libmain2.a main2.o
  </code></pre>
  
  <p>I then copy over the files and try build on the host machine with gcc 4.5.3 and get the following:</p>
  
  <pre><code>arm-angstrom-linux-gnueabi-g++ simple.cpp -lmain2 -L.
  </code></pre>
  
  <p>(I cleaned up some of the output)</p>
  
  <p><strong>undefined reference to `std::_Hash_bytes(void const*, unsigned int, unsigned int)'</strong>
  <strong>undefined reference to 
   std::__throw_regex_error(std::regex_constants::error_type)'</strong></p>
  
  <p>However, when I use nm, I get the following:</p>
  
  <pre><code>    $ arm-angstrom-linux-gnueabi-nm libmain2.a | grep Hash_bytes
       U _ZSt11_Hash_bytesPKvjj
       U _ZSt11_Hash_bytesPKvjj
      $ arm-angstrom-linux-gnueabi-nm libmain2.a | grep throw_regex
       U _ZSt19__throw_regex_errorNSt15regex_constants10error_typeE
       U _ZSt19__throw_regex_errorNSt15regex_constants10error_typeE
  </code></pre>
  
  <p>Does anyone know what the heck is going on? Unfortunately we need to be able to use our cross compiler on the host system for most work, but we are also needing to integrate this specific library which uses c++11.</p>
  
  <p>Also note that if I take out the regex and hash functionality from my code but leave other c++11 concepts like nullptr, type inference, delegation etc, the code compiles and runs on the target fine.</p>
  
  <p>Edit: Okay, so after a little more investigation, it looks like the functions _Hash_bytes and __throw_regex_error are not being statically linked into the static library. I guess I need to know why this is the case in order to fix the issue.</p>