title: Undefined symbols for architecture x86_64: when making a call to a C++ function in Xcode 8
body: <p>I am attempting to create a project in Xcode to access the OpenCV framework for eventual use with a Swift based app.</p>
  
  <p>At a high level, I have the OpenCV framework in C++, which interfaces with a C++ binding. Then, an Objective-C class wraps the binding, so that my Swift code can access it.</p>
  
  <p>However, while everything works fine in the editor, when I go to compile it, I receive the following error for each C++ function I have defined in my binding class.</p>
  
  <blockquote>
    <p>Undefined symbols for architecture x86_64:   "Library::multiply()",
    referenced from:+[ViewController multiply] in ViewController.o</p>
  </blockquote>
  
  <p>The following is a an abbreviated version of my project to illustrate the problem.</p>
  
  <p>First, the affected files:</p>
  
  <p><a href="https://i.stack.imgur.com/k36EH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k36EH.png" alt="enter image description here"></a></p>
  
  <p>As you can see, I have the proper suffix on my wrapper file ( <code>ViewController.mm</code> ).</p>
  
  <p>ViewController.mm contents:</p>
  
  <pre><code>#import "ViewController.h"
  #import "library.hpp"
  
  @implementation ViewController
  
  - (void)viewDidLoad {
      [super viewDidLoad];
  
      NSLog(@"Number: %f", Library().multiply());
  }
  
  @end
  </code></pre>
  
  <p>library.hpp contents:</p>
  
  <pre><code>#pragma once
  #include &lt;stdio.h&gt;
  
  class Library {
  public:
      Library();
      ~Library();
      double multiply();
  };
  </code></pre>
  
  <p>library.cpp contents:</p>
  
  <pre><code>#include "library.hpp"
  
  Library::Library() { }
  
  Library::~Library() { }
  
  double multiply() {
      return 1.0 * 2.0;
  }
  </code></pre>
  
  <p>Build settings related to C++:</p>
  
  <p><a href="https://i.stack.imgur.com/xnviL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xnviL.png" alt="enter image description here"></a></p>
  
  <p>** UPDATED **</p>
  
  <p>The answer posted by Harish Gupta is certainly correct, and did fix my issue. However, I did investigate further and came up with what I feel is a better solution for this at scale, which was to create a namespace for my C++ class, and then pull it into my <code>.mm</code> file with a <code>using</code> command.</p>