title: How to build and use a C++ static library for ios application
body: <p>I know how to build a object C static library using <code>iOS-&gt;Framework&amp;Library-&gt;Cocoa Touch Static Library</code> in xcode 4.6, and it is straightforward with the help of this tutorial <a href="http://www.raywenderlich.com/41377/creating-a-status-library-in-ios-tutorial" rel="noreferrer">Creating a Static Library in iOS Tutorial</a>. One thing I am not sure, however, is how to build and use a pure C++ static library for io application. For building a C++ static library, I am also use  <code>iOS-&gt;Framework&amp;Library-&gt;Cocoa Touch Static Library</code> guideline, and the difference is that I delete all the .h and .m files when creating the static library project and then put all the C++ static library head files and implementation files in the project. A very simple example is as follows:</p>
  
  <p>hello.h </p>
  
  <pre><code>#include &lt;iostream&gt;
  void say_hello();
  </code></pre>
  
  <p>hello.cpp</p>
  
  <pre><code>#include "hello.h"
  
  void say_hello()
  {
  std::cout&lt;&lt;"hello"&lt;&lt;std::endl;
  }
  </code></pre>
  
  <p>It seems working, and I can build <code>hello.a</code> static library for iPhone 6.1 Simulator. The next step is to build an application that will invoke the static library. I build a simple <code>iOS application-&gt;Single View Application</code> for iPhone 6.1 Simulator, and then try to invoke the  <code>hello.a</code> static library in <code>ViewController.mm</code> file (change ViewController.m to ViewController.mm so that it can invoke C++ function) simply with the following code:</p>
  
  <pre><code>say_hello();
  </code></pre>
  
  <p>However, I received one warning and two error messages:</p>
  
  <p>Warning:</p>
  
  <pre><code>ld: warning: ignoring file hello.a, file was built for archive which is not the architecture being linked (i386): 
  </code></pre>
  
  <p>Error 1:</p>
  
  <pre><code>hello.a
  Undefined symbols for architecture i386:
    "say_hello()", referenced from:
        -[ViewController viewDidLoad] in ViewController.o
  </code></pre>
  
  <p>Error 2:</p>
  
  <pre><code>ld: symbol(s) not found for architecture i386
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>I then have several questions related to this experiment:</p>
  
  <ul>
  <li>Is it the right way to create a pure C++ static library?</li>
  <li><p>Is there something wrong with the way how I invoke the C++ static
  library?</p></li>
  <li><p>In my example, when invoking the static library, how could I solve the link errors?</p></li>
  </ul>
  
  <p>Many thanks. </p>