Note that there are some explanatory texts on larger screens.

plurals
  1. PONative Client plugin using tesseract library
    text
    copied!<p>I'm trying to build a Native Client plugin for Chrome that will include the TesseractOCR library. I've compiled leptonica and tesseract (and appropriate dependencies) using the glibc NaCL toolchain for linux x86-64. All the dynamically-linked libraries are included in the nmf.</p> <p>When I actually try to load the plugin in chrome, I get the following error on the javascript console:</p> <pre><code>updateStatus() hello_tutorial.html:56 pageDidLoad if true hello_tutorial.html:39 NativeClient: NaCl module load failed: Nexe crashed during startup hello_tutorial.html:1 </code></pre> <p>I'm not sure if I've compiled something incorrectly or I'm attempting to do something that NaCL/Chrome can't handle. Any suggestions and help are greatly appreciated!</p> <p>I do get the LOADING... to display and such.</p> <p>I've disabled the nacl_gdb debugger in the Chrome flags (as suggested by <a href="https://groups.google.com/forum/?fromgroups#!topic/native-client-discuss/h-0RYn08WmE" rel="nofollow noreferrer">this post</a> and <a href="https://stackoverflow.com/questions/14191985/error-when-running-native-client-sdk-examples">this post</a>). I can compile and run the examples from the NaCL tutorials.</p> <p>This is the HTML file that loads the plugin:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;!-- Copyright (c) 2012 The Native Client Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --&gt; &lt;head&gt; &lt;title&gt;hello_tutorial&lt;/title&gt; &lt;script type="text/javascript"&gt; HelloTutorialModule = null; // Global application object. statusText = 'NO-STATUS'; // Indicate load success. function moduleDidLoad() { HelloTutorialModule = document.getElementById('hello_tutorial'); updateStatus('SUCCESS'); console.log("moduleDidLoad()"); } // The 'message' event handler. This handler is fired when the NaCl module // posts a message to the browser by calling PPB_Messaging.PostMessage() // (in C) or pp::Instance.PostMessage() (in C++). This implementation // simply displays the content of the message in an alert panel. function handleMessage(message_event) { alert(message_event.data); } // If the page loads before the Native Client module loads, then set the // status message indicating that the module is still loading. Otherwise, // do not change the status message. function pageDidLoad() { if (HelloTutorialModule == null) { updateStatus('LOADING...'); console.log("pageDidLoad if true"); } else { // It's possible that the Native Client module onload event fired // before the page's onload event. In this case, the status message // will reflect 'SUCCESS', but won't be displayed. This call will // display the current message. updateStatus(); console.log("pageDidLoad if false"); } } // Set the global status message. If the element with id 'statusField' // exists, then set its HTML to the status message as well. // opt_message The message test. If this is null or undefined, then // attempt to set the element with id 'statusField' to the value of // |statusText|. function updateStatus(opt_message) { console.log("updateStatus()"); if (opt_message) statusText = opt_message; var statusField = document.getElementById('status_field'); if (statusField) { if(statusField.innerHTML.indexOf("..." &gt;= 0)){ statusField.innerHTML = statusText.replace(".", ""); } else{ if(statusField.innerHTML.indexOf(".." &gt;= 0)){ statusField.innerHTML = statusText + "."; } else{ if(statusField.innerHTML.indexOf("." &gt;= 0)){ statusField.innerHTML = statusText + "."; } } } statusField.innerHTML = statusText; } } &lt;/script&gt; &lt;/head&gt; &lt;body onload="pageDidLoad()"&gt; &lt;h1&gt;Native Client Module HelloTutorial&lt;/h1&gt; &lt;p&gt; &lt;!-- Load the published .nexe. This includes the 'nacl' attribute which shows how to load multi-architecture modules. Each entry in the "nexes" object in the .nmf manifest file is a key-value pair: the key is the instruction set architecture ('x86-32', 'x86-64', etc.); the value is a URL for the desired NaCl module. To load the debug versions of your .nexes, set the 'nacl' attribute to the _dbg.nmf version of the manifest file. Note: Since this NaCl module does not use any real-estate in the browser, it's width and height are set to 0. Note: The &lt;EMBED&gt; element is wrapped inside a &lt;DIV&gt;, which has both a 'load' and a 'message' event listener attached. This wrapping method is used instead of attaching the event listeners directly to the &lt;EMBED&gt; element to ensure that the listeners are active before the NaCl module 'load' event fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or pp::Instance.PostMessage() (in C++) from within the initialization code in your NaCl module. --&gt; &lt;div id="listener"&gt; &lt;script type="text/javascript"&gt; var listener = document.getElementById('listener'); listener.addEventListener('load', moduleDidLoad, true); listener.addEventListener('message', handleMessage, true); &lt;/script&gt; &lt;embed name="nacl_module" id="hello_tutorial" width=0 height=0 src="hello_tutorial.nmf" type="application/x-nacl" /&gt; &lt;/div&gt; &lt;/p&gt; &lt;h2&gt;Status&lt;/h2&gt; &lt;div id="status_field"&gt;NO-STATUS&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>This is the C++ file I'm trying to compile for the plugin:</p> <pre><code>#include &lt;cstdio&gt; #include &lt;string&gt; #include "ppapi/cpp/instance.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/var.h" #include &lt;baseapi.h&gt; #include &lt;allheaders.h&gt; /// The Instance class. One of these exists for each instance of your NaCl /// module on the web page. The browser will ask the Module object to create /// a new Instance for each occurence of the &lt;embed&gt; tag that has these /// attributes: /// type="application/x-nacl" /// src="hello_tutorial.nmf" /// To communicate with the browser, you must override HandleMessage() for /// receiving messages from the browser, and use PostMessage() to send messages /// back to the browser. Note that this interface is asynchronous. class HelloTutorialInstance : public pp::Instance { public: /// The constructor creates the plugin-side instance. /// @param[in] instance the handle to the browser-side plugin instance. explicit HelloTutorialInstance(PP_Instance instance) : pp::Instance(instance) {} virtual ~HelloTutorialInstance() {} /// Handler for messages coming in from the browser via postMessage(). The /// @a var_message can contain anything: a JSON string; a string that encodes /// method names and arguments; etc. For example, you could use /// JSON.stringify in the browser to create a message that contains a method /// name and some parameters, something like this: /// var json_message = JSON.stringify({ "myMethod" : "3.14159" }); /// nacl_module.postMessage(json_message); /// On receipt of this message in @a var_message, you could parse the JSON to /// retrieve the method name, match it to a function call, and then call it /// with the parameter. /// @param[in] var_message The message posted by the browser. virtual void HandleMessage(const pp::Var&amp; var_message) { // TODO(sdk_user): 1. Make this function handle the incoming message. } }; /// The Module class. The browser calls the CreateInstance() method to create /// an instance of your NaCl module on the web page. The browser creates a new /// instance for each &lt;embed&gt; tag with type="application/x-nacl". class HelloTutorialModule : public pp::Module { public: HelloTutorialModule() : pp::Module() {} virtual ~HelloTutorialModule() {} /// Create and return a HelloTutorialInstance object. /// @param[in] instance The browser-side instance. /// @return the plugin-side instance. virtual pp::Instance* CreateInstance(PP_Instance instance) { return new HelloTutorialInstance(instance); } }; namespace pp { /// Factory function called by the browser when the module is first loaded. /// The browser keeps a singleton of this module. It calls the /// CreateInstance() method on the object you return to make instances. There /// is one instance per &lt;embed&gt; tag on the page. This is the main binding /// point for your NaCl module with the browser. Module* CreateModule() { return new HelloTutorialModule(); } } // namespace pp </code></pre> <p>The compiler command for it:</p> <pre><code>/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-g++ hello_tutorial.cc -o hello_tutorial_x86_64.nexe -I/var/www/native_client/projects/leptonica_src/src -I/var/www/native_client/projects/tesseract_build/include/tesseract -I/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/x86_64-nacl/usr/include/glib-2.0 -I/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/x86_64-nacl/usr/include/webp -I/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/x86_64-nacl/usr/include/libpng12 -I/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/x86_64-nacl/usr/include -I/var/www/native_client/projects/leptonica_src/src -I/var/www/native_client/nacl_sdk/pepper_26/include -L/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/x86_64-nacl/usr/lib -L/var/www/native_client/projects/leptonica_src/src/.libs -L/var/www/native_client/projects/tesseract_build/lib -lppapi_cpp -lppapi -pthread -lglib-2.0 -lstdc++ -ldl -lz -lwebp -lpng -ltesseract -llept -lnosys -lm </code></pre> <p>The commands I used to compile leptonica:</p> <pre><code>&gt; ./configure --host=nacl SOURCES="-I/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/x86_64-nacl/usr/include" AR="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/x86_64-nacl/bin/ar" CC="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-g++" CFLAGS=" -g -O2 -fPIC -I/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/x86_64-nacl/usr/include/webp -I/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/x86_64-nacl/usr/include" CPP="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-g++ -E" CXX="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-g++" CXXCPP="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-g++ -E" CXXFLAGS="-g -O2 -fPIC " LD="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-ld -L /var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/x86_64-nacl/usr/lib -lplatform -ldl" NM="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-nm -B" OBJDUMP="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-objdump" RANLIB="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-ranlib" ac_ct_CXX="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-g++" &gt; MAKE </code></pre> <p>Compiling Tesseract</p> <pre><code>&gt; ./configure --host=nacl --prefix=/var/www/native_client/projects/tesseract_build SOURCES="-I/var/www/native_client/projects/leptonica_src_compiled_x86-64/src" AR="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/x86_64-nacl/bin/ar" CC="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-g++" CFLAGS=" -g -O2 -fPIC -I/var/www/native_client/projects/leptonica_src_compiled_x86-64/src" CPP="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-g++ -E" CXX="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-g++" CXXCPP="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-g++ -E" CXXFLAGS="-g -O2 -fPIC -I/var/www/native_client/projects/leptonica_src_compiled_x86-64/src" LD="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-ld -L/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/x86_64-nacl/usr/lib -L/var/www/native_client/projects/leptonica_src_compiled_x86-64/src/.libs -lplatform -ldl" LIBLEPT_HEADERSDIR="/var/www/native_client/projects/leptonica_src_compiled_x86-64/src" LIBS="-L/var/www/native_client/projects/leptonica_src/src/.libs -L/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/x86_64-nacl/usr/lib -llept -lpng -lwebp -lz" NM="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-nm -B" OBJDUMP="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-objdump" RANLIB="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-ranlib" ac_ct_CXX="/var/www/native_client/nacl_sdk/pepper_26/toolchain/linux_x86_glibc/bin/x86_64-nacl-g++" &gt; MAKE </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload