How do you use existing C libraries with the Chrome Native Client? - google-chrome

I'm new to Chrome Application development and the Native Client/PNaCL pipeline. I'm a bit confused over the process of using existing C code/libraries in a chrome application. The FAQs and NaCL official docs suggest that using existing code is easy, and one of the advantages of developing Chrome applications.
However, there is also mention of nacl-ports, an official list of ported C libraries to be used in Native Client apps.
If I have some random C library I've used, what is the process for actually using it in my Chrome application? This question feels silly, but I'm quite confused over the process. Do I have to recompile the source with a NaCL compiler? Where in the SDK can I find this?
The FAQ also mentions that things like forks, file i/o is not allowed in the library, so I will have to rewrite any code that does these things, is that correct?
Bottomline: I have an existing C library. What is the process for using it correctly, and making calls to it, in a Chrome application?

The short answer is that you'll have to recompile your library with a NaCl C compiler.
You may want to take a look at naclports: this repository contains ports of many common C libraries to Native Client. You can browse the source more easily here.
As for File I/O, we often suggest using the nacl_io library when porting existing code. This provides a POSIX interface (e.g. fopen/fclose/fread, etc.) Many ported libraries require no modifications when using nacl_io.

Related

Integration of IBM Rhapsody with IAR Workbench using the property (.prp) files

I want to integrate IBM Rhapsody with IAR Workbench so that, I will be able to use the Code generated in Rhapsody with the compilers of IAR. One way I found was using the .prp files of Rhapsody. I am unaware of using the .prp files.
There is a (not very informative) manual on adapting Rhapsody. (Try searching "adapter" in the Rhapsody help.)
You are very scarce with information however, adapting your Rhapsody to use a certain compiler depends on a lot more then just the compiler.
Do you want to use C or C++? What RTOS are you using? What CPU do you use (IAR makes compilers for many CPU's)
You can also check, there are companies that deliver turn-key adapters for Rhapsody.
Walter
Rhapsody supports workflow and platform integration with Eclipse. IAR Workbench also has Eclipse plugin.
You can start by installing Rhapsody Workflow integration plugin in your Eclipse, create Eclipse configuration in Rhapsody and generate code for this configuration.
This way you will also create Eclipse project. Try to build that project to discover what should be modified. The project should include paths, Rhapsody Framework's missing libraries, etc.
From this point on you can ask more specific questions regarding Rhapsody customization. .prp files are only one of possible ways.
BTW, which Rhapsody framework and language do you want to use? There are
OXF C++
SXFC++
OXF C
MXf C
SMXF C

Can I make calls to APIs such as youtube-dl and ffmpeg from a chrome-app?

First of all, I haven't started the implementation of the system I'm about to describe, as I didn't want to commit on implementing something I did not know if was possible.
So, what I'm trying to achieve is to build a chrome-app to download the audio from certain websites (e.g. youtube and soundcloud) using youtube-dl, post process it using ffmpeg and then upload it to a cloud service via some api. The reason I want to do it via a chrome-app is because I could do all the work on the client side (no need for servers) and I'd have the ability to insert javascript into the pages using content scripts, which would make the app pretty simple to use (I could create buttons such as 'download song' and stuff like that).
Although I have already read the documentation explaining the NaCl Technical Overview and some of the Application Structure, I still am not sure as to whether I would be able to make these calls via some C/C++ module or if I would get denied due to security reasons.
To summarize: considering that the user has the needed dependencies in his system (youtube-dl, python, ffmpeg and etc.), is it possible to make calls to third party APIs such as the ones described before via a chrome-app using NaCl ?
Thank you all in advance,
Chrome apps are normally sandboxed.
Less so than extensions - they can reach much more system resources via app APIs.
But still, what you mention is executing libraries / utilities out of browser, and it's not normally allowed.
(P)NaCl is tightly sandboxed in this regard. See this old question, it still applies: you can only use 3rd-party code that compiles into NaCl along with your app, not just link to a library. There are some library ports to NaCl, but it's not automatic.
Normally, a few years back you would use a mechanism like NPAPI to reach out and use a library out of browser. It's deprecated, and won't work anymore. In its place, Chrome offers a pipe-like (through stdio) connection to an external program called Native Messaging. You could use it to perform operations with system-level libraries and tools, but the downside is that you can't bundle the native host with your app, you'll need a separate installer.

Should we place C code in Static library or Runtime component?

We're moving to Windows Phone 8. But since many good libraries out there are in pure C. So what is the best way for Windows Phone C# application to consume this C library?
Place C code in WP Static library. Then reference it from WP Runtime
component
Place C code in WP Runtime component
What is the best practice ?
There isn't any real difference between the two approaches. A static library is nothing but a collection of .obj files, the exact same kind of .obj files that you'll get from approach #2. After the linker is done, there won't be any difference in the result.
That's when everything is perfect, an ideal that can be very difficult to achieve when you use open source C code. An advantage of a static .lib is that it improves build time, not having to re-generate the .obj files. But that's also their disadvantage, you'll shoot your foot if you use a .lib that was created by somebody else and he didn't use the same compiler version or compile options. The simplest example of such a trap is building your Debug version and the .lib was built for Release. Or if it uses winapi functions that are verboten in a Phone app, pretty common. So #3 is the best way to avoid problems, build the .lib yourself so you can control all the compile and link settings. Do beware however that it can be very difficult to get open source C code to build, it often comes with a very extensive configuration script, designed to deal with the differences between the many architecture and Unix variants.

Chrome browser extensions - hooking into C functions?

I'm writing a Chrome extension and some parts of it need to be super high performance. I'm trying to find documentation to see if it's possible to use C extensions within the Chrome extension. Is this currently possible?
Take a look at Native Client. You can write browser/web apps with NaCl via C or C++ (and Mono since 2.10). You can find a small tutorial here.

Best portable development platform for small personal project

I'm looking for a development platform (language and set of libraries) that will allow me to develop a personal project. (In case anyone is curious, I'm looking at making a music library manager, similar to iTunes, that can work on multiple platforms and sync with Android devices).
I want the language to have the following characteristics:
Essential
The program must run flawlessly, with no (or very little) code changes on Mac, Linux, and Windows. That means, notably, that I need to have a cross-platform GUI framework, a consistent API for accessing files and directories, and a consistent interface for talking to USB storage devices
Important
A language that is easy to use, powerful, and expressive. Big standard libraries with a lot of built-in functionality. (I'd probably use C#/.NET but the portability isn't great)
Nice to have
Good tool support (on Linux if possible, but I'll do my development on Windows if needs be)
Not Java. (I have used it and just don't like it - I'm not interested in getting into a language war here).
Please help me choose a language!
Python
Cross platform GUI: more than one option, I'd use WxPython, but Qt bindings are also available (comparison between wxWidgets and Qt).
File System API: this gets into the os package, but there are also convenience methods for just dealing with I/O.
USB I/O: I confess to not having any knowledge here, but suspect if you're talking storage that Python will be able to read and write using its IO package.
Libraries, Ease of Use, etc..: there's a lot built in, but also a huge number of add-ons (called "packages"). Some of the most notable are SciPy and NumPy, used for scientific and numerical analysis.
Tooling: there are a number of IDEs out there, I use PyDev (but it's Eclipse based so you probably won't like it if you don't like Java).
Finally, Python is supported on Android via its scripting environment.
For cross platform GUI, you can explore QT. The back-end can be on c.
Have you explored anything so far?
Qt quick ?