-2

I need a dummy .so file in order to call it's functions in android. The dummy .so file could be anything from doing addition, subtraction, etc. When searched online, All I find is "What is .so file?", "How to integrate .so file in android". Can anyone please share a dummy .so file for doing addition?

1 Answers1

0

It's my first shared library, and it was quie easy to do. I've applied this toutorial.

Here is my code:

lib.h

#pragma once

int sum(const int a, const int b);

lib.cpp

#include "lib.h"

int sum(const int a, const int b)
{
    return a+b;
}

main.cpp

#include "lib.h"
#include <iostream>

int main()
{
    std::cout << sum(10, 20) << std::endl;
    return 0;
}

and with theese commands i've vreated one:

# generating simple library
c++ -c -Wall -Werror -fPIC lib.cpp

# making it shared
c++ -shared -o libsum.so lib.o

Now you will have shared library, for making this program work i have to do 2 additional commands:

# create executable
g++ -L. main.cpp -l:libsum.so -o main

# if you try to run this command it will fail
./main

# so i've set ld path, but in the link above there are alternative solutions to that
export LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH

# now it should work, in my case output is: 30
./main
  • if you still have problem to achieve this, [here](https://drive.google.com/drive/folders/1_1kNtE-zQX2Rrsxxtr9JNS4A62MIAgwR?usp=sharing) is my output – Krzysztof Mochocki Aug 31 '20 at 10:02