title: Nodejs addon static library link: missing symbols
body: <p>Its been a few years since I've done some C++ development.  I'm trying to statically link the boost regex library and I'm getting the following errors when running </p>
  
  <blockquote>
    <p>node addon.js</p>
  </blockquote>
  
  <p>(i'm using the node-addon-examples/2_function_arguments example)</p>
  
  <pre><code> node addon.js
  dyld: lazy symbol binding failed: Symbol not found: __ZN5boost16re_detail_10600012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE14construct_initERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsE
    Referenced from: /Users/sjoseph/code/nodejs/addons/node-addon-examples/2_function_arguments/boost/build/Release/addon.node
    Expected in: dynamic lookup
  
  dyld: Symbol not found: __ZN5boost16re_detail_10600012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE14construct_initERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsE
    Referenced from: /Users/sjoseph/code/nodejs/addons/node-addon-examples/2_function_arguments/boost/build/Release/addon.node
    Expected in: dynamic lookup
  </code></pre>
  
  <p>I'm on macosx</p>
  
  <pre><code>nodejs: v4.3.0
   g++ --version
  Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
  Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
  Target: x86_64-apple-darwin14.3.0
  Thread model: posix
  </code></pre>
  
  <p>binding.gyp:</p>
  
  <pre><code>{
    "targets": [
      {
        "target_name": "addon",
        "sources": [ "addon.cc" ],
        "include_dirs":[
          "/usr/local/Cellar/boost/1.60.0/include"
          ],
        "link_settings":{
          "libraries":[
          "/usr/local/Cellar/boost/1.60.0/lib/libboost_regex.a"
          ],
        }
      }
    ]
  }
  </code></pre>
  
  <p>addon.cc</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;node.h&gt;
  #include &lt;boost/regex.hpp&gt;
  
  using std::string;
  using namespace std;
  using namespace v8;
  
  void Add(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);
  
    if (args.Length() &lt; 2) {
      isolate-&gt;ThrowException(Exception::TypeError(
          String::NewFromUtf8(isolate, "Wrong number of arguments")));
      return;
    }
  
    if (!args[0]-&gt;IsNumber() || !args[1]-&gt;IsNumber()) {
      isolate-&gt;ThrowException(Exception::TypeError(
          String::NewFromUtf8(isolate, "Wrong arguments")));
      return;
    }
  
    double value = args[0]-&gt;NumberValue() + args[1]-&gt;NumberValue();
    Local&lt;Number&gt; num = Number::New(isolate, value);
  
    args.GetReturnValue().Set(num);
  
  std::string s = "Boost Libraries";
    boost::regex expr{"(\\w+)\\s(\\w+)"};
    boost::smatch what;
    if (boost::regex_search(s, what, expr))
    {
      std::cout &lt;&lt; what[0] &lt;&lt; '\n';
      std::cout &lt;&lt; what[1] &lt;&lt; "_" &lt;&lt; what[2] &lt;&lt; '\n';
    } 
  }
  
  void Init(Handle&lt;Object&gt; exports) {
    NODE_SET_METHOD(exports, "add", Add);
  }
  
  NODE_MODULE(addon, Init)
  </code></pre>
  
  <p>addon.js</p>
  
  <pre><code>var addon = require('bindings')('addon.node')
  
  console.log('This should be eight:', addon.add(3, 5))
  </code></pre>
  
  <p>Note: dynamically linking the library also causes problems.</p>
  
  <p>Question: Do I need to compile nodejs &amp; boost using the same compiler?</p>