Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed NDK Help: How to call a C++ function for shared library from another project that uses C++
    text
    copied!<p>I am badly pulling my hair as not able to figure out (even though searched a lot on google). Please help</p> <p><strong>Situation:</strong></p> <ol> <li>I have a shared library. Let's say foo.so (Code completely in C++)</li> <li>Now in a new project, I want to use this shared library foo.so</li> <li>The new project code is also in C++. Let's say new project name is fooMate.</li> <li>I want to call the functions of functions or to use classes of foo in fooMate project cpp files without including the actual source code of foo project (i.e. by just using the foo.so file)</li> </ol> <p><strong>Question:</strong> How can we achieve this?</p> <p><strong>For Example:</strong></p> <pre><code>class foo { const char* giveMeAString(); } #include “foo.h” const char* foo::giveMeAString() { return “Hello World!”; } </code></pre> <p>Now I have compiled foo class successfully in shared library called: foo.so</p> <ol> <li><p>Now suppose I am writing another project which is also having some CPP code. But this new CPP code wants to reuse the static library.</p> <p>// Declaration</p></li> </ol> <blockquote> <p>class fooMate { void printDemo(); }</p> </blockquote> <p>// Implementation</p> <pre><code>#include “fooMate.h” #include “foo.h” void fooMate::printDemo() { foo *testFoo = new foo(); cout&lt;&lt;giveMeAString(); } </code></pre> <p>How can I achieve this by using foo.so file instead of using actual source code of foo.cpp</p> <p><strong>Here is the Android.mk file that I am using</strong></p> <pre><code>#Adding foo.so file in project. LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := foo-lib-module LOCAL_SRC_FILES := foo-lib.so LOCAL_EXPORT_C_INCLUDES := include include $(PREBUILT_SHARED_LIBRARY) #New Project and Source code include $(CLEAR_VARS) LOCAL_MODULE := foomate-module LOCAL_MODULE_FILENAME := foomate-lib LOCAL_SRC_FILES := fooMate.cpp LOCAL_C_INCLUDES := $(LOCAL_PATH)/Classes/include include $(BUILD_SHARED_LIBRARY) </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