I am completely new to Native Client and unfortunately I am also quite inexperienced with 'make', compiling etc., so I hope you may give me some basic information on how to approach my
problem.
So what I am trying to accomplish is compiling a C++ library for using it in a NaCl application.
First I have my application based on the examples delivered with Pepper, which I simply compile using the attached 'make.bat'.
Well then I downloaded the source code of the library, containing folders like 'config' and 'src', so first i would have to call 'configure', 'make', 'make install'. But i would like to let the library compile with that 'make.bat', so I guess I would have to append the complex configure/Makefile scripts of the library to the Makefile of my NaCl application?
How can that be done?
Where can i find useful information and/or help?
Thank you!
You can look to nacl ports project to see how porting libraries to NaCl can be done. NaCl ports works best on Linux platform, so you better have a virtual machine with it or work on it directly.
There is one more trick to port libraries. People create wrapper scripts around compiler and linker. These wrapper scripts call nacl compiler and linker but they also create a shell script that calls the resulting NaCl executable using sel_ldr. This script is returned instead of executable (this is Linux-only trick). This way configure and make can execute NaCl code and do not suspect anything. So normal configure/make process can be used, we just need to set compiler and linker to these wrapper scripts.
Since you are probably not going to develop library itself, it is best to compile it once and then use it in your makefile. Add -l option with the name of your library and -L option with path to library directory. You can use GLIBC_LDFLAGS variable in the example makefile for these options.
Did you know that you can use Visual Studio to developer NaCl applications?
http://mainroach.blogspot.com/2012/10/official-nacl-vs2010-add-in-available.html
Related
So you can compile openssl into you C++ project for example, and make everything as a single .exe file. Is this the correct way to do it?
Or should we instead just copy and paste openssl.exe command line utility into the exe location of our program and instead in our program call the openssl commands? Example("openssl enc -aes-cbc-256.....")
Im working on a bigger project and don't want to make this newbie mistake. I see for example NordVpn has in it's install location openssl.exe that seems to not be compiled into their .exe?
It depends on what kind of project you are doing. You would dynamically or statically link openssl (you can read about the advantages/disadvantages everywhere). Please consider to use a different library, something that is easier to use. I would recommend https://libsodium.gitbook.io/doc/. In my opinion it is better for beginners.
If you have security concerns, read this: https://security.stackexchange.com/a/94629
If what you are after is secure encryption/decryption of data in your application, I'd strongly recommend 1) compiling your own OpenSSL libraries (or whichever encryption library you choose), and 2) static linking them into your application.
A call out to an external tool is much less secure. And you can't even be sure that the external tool binary your app calls will be the same one you originally distributed.
I developed a Qt application in MacBook (El-Capitan 10.11.2) and it is ready now to be released.
What i want now, is to create the standalone executable file for both Mac and Windows OS.
But I don't know how !
I found this link but I am unable to follow it is guidance, it looks different from what my system is showing me.
If you have any idea, please help me.
Thank you
Well, to compile an application for windows, you will need a windows machine (or at least a virtual machine). You can't compile for windows on mac.
Regarding the "standalone": The easy way is to deploy your application together with all the required dlls/frameworks and ship them as one "package". To to this, there are the tools windeployqt and macdeployqt. However, those will not be "single file" applications, but rather a collection of files.
If you want to have one single file, you will have to build Qt statically! You can to this, but you will have to do it on your own. And if you do, please notice that the LGPL-license (the one for the free version of Qt) requires you to make the source-code of your program public! That's not the case if you just link to the dynamic libraries.
EDIT:
Deployment
Deployment can be really hard, because you have to do it differently for each platform. Most times you will have 3 steps
Dependency resolving: In this step, you collect all the exectuables/lirabries/translations/... your application requires and collect them somewhere they can find each other. For windows and mac, this can be done using the tools I mentioned above.
Installation: Here you will have to create some kind of "installer". The easiest way is to create a zip-file that contains everyhing you need. But if you want to have a "nice" installation, you will have to create proper "installers" for each platform. (One of many possibilities is the Qt Installer Framework. Best thing about it: It's cross platform.)
Distribution: Distribution is how to get your program to the user. On Mac, you will have the App-Store, for windows you don't. Best way is to provide the download on a website created for this (like sourceforge, github, ...)
I can help you with the first step, but for the second step you will have to research the possibilities and decide for a way to do it.
Dependencies
Resolving the dependencies can be done by either building Qt statically (this way you will have only one single file, but gain additional work because you will have to compile Qt) or using the dynamic build. For the dynamic build, Qt will help you to resolve the dependencies:
macdeployqt is rather easy to use. Compile your app in release mode and call <qt_install_dir>/bin/macdeployqt <path_to_your_bundle>/<bundle>.app. After thats done, all Qt libraries are stored inside the <bundle>.app folder.
For windeployqt is basically the same: <qt_install_dir>\bin\windeployqt --release <path_to_your_build>\<application>.exe. All dependencies will be inside the build folder. (Hint: copy the <application>.exe in an empty directoy and run windeployqt on that path instead. This way you get rid of all the build-files).
Regarding the static build: Just google it, you will find hundreds of explanations for any platform. But unless you have no other choice but to use one single file (for whatever reason) it would recommend you to use dynamic builds. And regarding the user experience: On mac, they won't notice a difference, since in both cases everything will be hidden inside the app bundle. On windows, it's normal to have multiple files, so no one will bother. (And if you create an installer for windows, just make sure to add a desktop shortcut. This way the user will to have "a single file" to click.)
I have a NPAPI plugin that is used for Screen-sharing.
For that I am using zlib, jpeg, tight-vnc libraries along with a library(say libX) that is developed by me.
Now I wish to port it to NaCl.
libX has structure like:
/X/commonfiles
/X/win/*.cpp *.h
/X/linux/*.cpp *.h
/X/mac/*.cpp *.h *.mm
These directories contain cpp files specific to the platform.
I make use of makefiles to compile them according to the platform.
But I am unable to understand how NaCl toolchain will generate a nexe or pexe from my library/code.
Is there any makefile we have to consider or any other thing I'm missing.
Please Help!
Thanks!!!
First, NaCl is a sandboxing technology that provides security when running native code in a browser. As such, you will not be able to access the user's filesystem directly (as you would be able to with an NPAPI plugin). You may need to modify your library to support NaCl as a new "operating system".
That said, a lot of functionality is available through the Pepper Plugin API (PPAPI), which allows your NaCl plugin to communicate with the browser. In addition, the nacl_io library that comes with the NaCl SDK provides a more familiar POSIX-like interface, to support File I/O and sockets.
It shouldn't be too hard to try building your library using the pnacl toolchain as follows:
Download the Native Client SDK. When you're done, you should have a directory called pepper_31 that contains the Native Client SDK.
The Native Client build will likely be most similar to your Linux port. In your makefile, change any build rule that executes your native toolchain to use the pnacl toolchain instead, e.g.
g++ => pepper_31/toolchain/linux_pnacl/bin/pnacl-clang++
ar => pepper_31/toolchain/linux_pnacl/bin/pnacl-ar
etc.
Try building your Linux build. You probably will have some compilation failures, maybe from missing libraries, maybe from header differences. Depending on what your library does, you may need to modify it to use the PPAPI, to access things like graphics, sockets, URL requests, File IO, etc.
Once you do this, you'll likely have some more specific questions about how to implement features that you need. :)
What is MakeFile in Eclipse? From the documentation:
A makefile is a text file that is referenced by the make command that
describes the building of targets, and contains information such as
source-level dependencies and build-order dependencies. The CDT can
generate a makefile for you, such projects are called Managed Make
projects. Some projects, known as Standard Make projects, allow you to
define your own makefile.
But the explanation does not help me understand what a MakeFile is. I am moving from VisualStudio/C# to Eclipse/C++. Is MakeFile analogous to Visual Studio's Metadata? When do I need to write a MakeFile, and why do I need it besides the C++ code?
[EDIT]
I used to develop on Windows with VS and C#. And now trying Eclipse/C++ on a Mac. I have never build anyone on Linux. So the answer I have read so far does not help explain anything at all.
A makefile in the simplest terms is a file that builds a program. These are normally used from the command line. If you have ever built something on linux you may have run ./configure ; make ; make install. You are using a makefile there.
More info...
https://en.wikipedia.org/wiki/Make_(software)
In simple terms: Make helps you create cross-platform configuration settings in one file, and it will work on surprisingly many platforms, including Windows or Mac OS-es.
Mentioning Windows, you should have Make installed on the computer you're installing on (on Windows, Cygwin and MinGW include Make). It's required only if the user will actually build the code from the source.
But of course, you should include Make code for each different platform (e.g. one for Unix-like, one for Windows, etc.)
I have written and tested a library in C++. The code even works in my Android application if I add the source files directly. While I do have experience compiling static and dynamic libraries for common operating systems, I have zero experience compiling for a mobile system like this. I've done some research, and I'm still a bit lost as to exactly how to approach this. For example, I am unsure of whether to build a makefile for use with ndk-build or to just invoke one of the Android's compilers directly.
I did see this question, but it does not quite match my situation. I just want to run build and have it spit out libfoo.a (I'd like to produce libfoo.so as well, but libfoo.a is of greater interest to me right now.) The example in that question's winning answer implied that it would build the library as one step/module for building the final application. I tried doing it that way just to see, but I had no luck.
Can anyone please guide me in this endeavor?
CLARIFICATION -- I do not want to build the library and immediately pipe it into an application. I want a .a or .so file that I can link against in multiple future Android applications.
Create a dummy java file with empty code and make sure there is a android_main function in your C++ code. Build using ndk-build. the resulting apk will make your library an application.
See the samples from the android-ndk-r5/samples directory, see the sample native-bitmap to get some idea.
If I understand it correctly that a shared library is not acceptable and you want to be static (but why is that so important?), probably the easiest way to do so is to simply supply source code that can be added to a project.
Ultimately there is nothing special about the ndk build system other than it knowing the right commands to issue to build the necessary files for the assortment of curent android architectures. If you really want to do something different, you can log the operation of the android build system in creating a shared library, and then write your own Makefile that performs the analogous steps to create a static library. HOWEVER, you will have to update your Makefile any time the underlying assumptions or target collections change in a new android version.