title: How to provide js-ctypes in a spidermonkey embedding?
body: <p><strong>Summary</strong></p>
  
  <p>I have looked over the code the SpiderMonkey 'shell' application uses to create the ctypes JavaScript object, but I'm a less-than novice C programmer. Due to the varying levels of insanity emitted by modern build systems, I can't seem to track down the code or command that actually links a program with the desired functionality.</p>
  
  <hr>
  
  <p><strong>method.madness</strong></p>
  
  <p>This js-ctypes implementation by The Mozilla Devs is an awesome addition. Since its conception, scripting has been primarily used to exert control over more rigorous and robust applications. The advent of js-ctypes to the SpiderMonkey project, enables JavaScript to stand up and be counted as a full fledged object oriented rapid application development language flying high above 'the bar' set by various venerable application development languages such as Microsoft's VB6.</p>
  
  <hr>
  
  <p><strong>Shall we begin?</strong></p>
  
  <p>I built SpiderMonkey with this config: ./configure --enable-ctypes --with-system-nspr</p>
  
  <p>followed by successful execution of: make &amp;&amp; make install</p>
  
  <p>The js shell works fine and a global ctypes javascript object was verified operational in that shell.</p>
  
  <p>Working with code taken from the first source listing at <a href="https://developer.mozilla.org/en/How_to_embed_the_JavaScript_engine" rel="nofollow">How to embed the JavaScript Engine -MDN</a>, I made an attempt to instantiate the JavaScript ctypes object by inserting the following code at line 66:</p>
  
  <pre><code>    /* Populate the global object with the ctypes object. */
      if (!JS_InitCTypesClass(cx, global))
          return NULL;
      /*
  </code></pre>
  
  <p>I compiled with: g++ $(./js-config  --cflags --libs) hello.cpp -o hello</p>
  
  <p>It compiles with a few warnings:</p>
  
  <pre><code>hello.cpp: In function ‘int main(int, const char**)’:
  hello.cpp:69:16: warning: converting to non-pointer type ‘int’ from NULL [-Wconversion-null]
  hello.cpp:80:20: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  hello.cpp:89:17: warning: NULL used in arithmetic [-Wpointer-arith]
  </code></pre>
  
  <p>But when you run the application:</p>
  
  <pre><code>./hello: symbol lookup error: ./hello: undefined symbol: JS_InitCTypesClass
  </code></pre>
  
  <hr>
  
  <p><strong>Moreover</strong></p>
  
  <p>JS_InitCTypesClass is declared extern in 'dist/include/jsapi.h', but the function resides in 'ctypes/CTypes.cpp' which includes its own header 'CTypes.h' and is compiled at some point by some command during 'make' to yeild './CTypes.o'. As I stated earlier, I am less than a novice with the C code, and I really have no idea what to do here.</p>
  
  <p>Please give or give direction to a generic example of making the js-ctypes object functional in an embedding.</p>