how to add cpp/h file to android NDK CMakeLists.txt ? - android-ndk

I created new project support C++
I created new class
- myClass.h
- myClass.cpp
And i can't find any way to include this class on the CMakeLists.txt
any help please ..
10x

If you already have CMakeList.txt for your project at correct level then you can just add .cpp filenames to your target.
add_library(libraryName SHARED myClass.cpp)
You can see NDK samples for more details (adding android libraries etc.)
If you have never written CMake file then lookup appropriate documentation for it.

Related

How to import 3rd party binary library in Android Studio 3.4?

Backgroud:
I would like to use a third-party library in Android Studio 3.4. The library includes three files:see pics
arm64-v8a/libAnalyticsLib.so
armeabi-v7a/libAnalyticsLib.so
StrideAnalyticsLib.jar.
The class files within "StrideAnalyticsLib.jar" show that they seem to be generated by using SWIG.
I've tried two ways to import this library but still cannot
import StrideAnalyticsLib.*;
But this doesn't allow to access the classes and shows "cannot
resolve symbol ...".
the .so files are with jniLibs
~/main/jniLibs/
~/main/jniLibs/arm64-v8a/libAnalyticsLib.so
~/main/jniLibs/armeabi/libAnalyticsLib.so
the .so files are within libs; At the same time, i added "sourceSets { main{ jniLibs.srcDirs = ['libs']}}" in build.gradle;
~/libs/
~/libs/arm64-v8a/libAnalyticsLib.so
~/libs/armeabi/libAnalyticsLib.so
Both attempts are followed by cleaning and rebuilding the project.I'm very new to Android and couldn't get it work. Could anyone please provide help? Great Thanks!
After I studied the process using SWIG to wrap c/c++ library into the .jar and .so., I realised that the .jar and .so will have same package name so that the .jar can call the .so file.
Because my .jar doesn't work when it's saved in /libs, I instead copied all classes within the .jar and pasted them into the /main folder. Remember to put them outside your package, otherwise the package name of these classes will be changed, which cause my problem. The way of importing .so is correct. Just put the .so files inside /main/jniLibs.

Can I build static library that main component is header file(.h) with NDK?

I want to convert my cpp code for static library into Android library.
For this, I'm attempting to use NDK.
But I read NDK documentation and it said that only source code is able to be input for building, "Android.mk".
My Questtion is "Is there any way to build static library for Android system with my cpp library?"
Top module of my cpp library is header file and it can be built on Windows system as ".lib".
Thank you!
Your cpp library should be built with NDK toolchain as "libyourname.a" to begin with. You don't need Android.mk for that, even though in many cases deriving a standards-compliant Android.mk is trivial, and makes the developer's life happier in the long run (See, e.g., github).
The next step should be to prepare a JNI wrapper dynamic library (shared object, .so), which can be loaded from your Java app. That "libyourname_jni.so" will probably have its own, separate Android.mk file. Well, Java is not a must: you can use NativeActivity, or maybe some alternative frameworks.
I suggest the following reading to understand the whole process: http://thesoftwarerogue.blogspot.co.il/2010/05/porting-of-libcurl-to-android-os-using.html

Visual Studio 2008 c++ linker refuses to link?

I am banging my head against a wall here.
All i want is to link a static .lib file in a cpp windows forms application! So, i have an include folder in my project folder that holds header files for that .lib (lib is Yaml-cpp if someone wonders). And i have a lib folder that has the .lib files for that library.
I tested it on a blank project
1.I make a new windows forms project in VS2008, in C++.
2.I go to project properties - c/c++ general and additional include directories that have yaml-cpp header files
3.I go to linker and add path to my lib directory
4.I go to linker - input and add my .lib file
5.I check linker command line and it contains my .lib file so it must be all set.
6.Then i write the sample code in an onbutton function body (which appears in form1.h fie).
Sample code is from here http://code.google.com/p/yaml-cpp/wiki/HowToParseADocument and its just as simple as:
#include <fstream>
#include "yaml.h"
and then:
std::ifstream fin("test.yaml");
YAML::Parser parser(fin);
YAML::Node doc;
while(parser.GetNextDocument(doc)) {
//do nothing yet
}
7.And then i compile and have 10 "unresolved externals".
I have looked into another project that uses same library, and it has exactly same directory structure, same name of .lib added in linker - input - additional dependencies, same .lib and .h files. And it works for that project- but it doesnt work for me.
What in the world is wrong?
EDIT: I tried making new windows 32 console application and it worked correctly. I then tried to make another fresh windows forms application and it failed.
It is confirmed now. Same steps for linking a library work in console application and fail in windows forms application. WHY?
What you've done seems correct from your explanation, let's do some blind troubleshooting.
Try giving full path instead of relative path for library path and additional include directories. (but as u said that the file is getting read, that should be the problem.)
If you are using a copy of original libyaml-cppmdd.lib and its include file, check whether the header file that gets included is of the same version as the lib.
Check whether there are any functions in any part of the code that is having a declaration but no definition.
Check whether you're accessing any private functions from the library.
Please read this Microsoft article on Troubleshooting UnResolved External Symbol error.
Hope it helps!

generating .so file instead of .exe in qt4.7 on linux

I have built a simple GUI application in QtCreator-2.0.1 i have following files:
first.pro
first.pro.user
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
If I run qmake and make it gives me an executable. Is it possible to generate a .so file from these files? if so, can someone tell me the steps to be followed?
Are you trying to build a shared library ? A plugin ?
When you created your project with Qt Creator, which kind of project did you choose ?
In your case, I guess you wanted to choose Other Project->C++ Library (you can then choose if you want a shared library or a Qt 4 plugin.
Anyway, from your project, I guess you'll have to change the template in your .pro and put :
TEMPLATE = lib

Call Boost libraries in C++

I have built the Boost library from these instructions:
http://stackoverflow.com/questions/3529163/install-boost-library-in-visual-c-2008
Directory of the unzipped Boost folder is C:\Users\David\Desktop\boost_1_44_0. I have called Visual C++ 2010. How to use Boost in a program?
I mean I want the following.
#include<boost>
Tweak your project properties to add C:\Users\David\Desktop\boost_1_44_0 to the include path and maybe the link path if you plan to use the part of Boost that is not include-only (libboost_filesystem for instance).
You have to include the header path and library path in your project.
Also #include <boost> won't do anything. You have to include each individual feature of boost that you need. For instance if you need to link to the filesystem.lib file in to boost directory, and use #include "boost/filesystem.hpp".
Take a look at this answer from step 6: Another Answer

Resources