[WISH] Compiler support for .so library files

wonder

Expert
Licensed User
Longtime User
So, I have the following kind of "Hello World" C++ project going on here: http://cpp.sh/2ttqh
B4X:
// Example program Distance Between two points in 2D space.
#include <iostream>
#include <math.h>

long distance_between(long x1, long x2, long y1, long y2);

int main()
{
  // this is just an example
  std::cout << distance_between(123, 456, 789, 101) << "\n";
}

long distance_between(long x1, long x2, long y1, long y2)
{
    return sqrt( ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1)) );
}


...and I would like to have a head-to-head performance comparison with its B4A counterpart:
B4X:
Sub DistanceBetween(x1 as Long, x2 as Long, y1 as Long, y2 as Long) as Long
    Return Sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)))
End Sub

How to do it?
 

walterf25

Expert
Licensed User
Longtime User
So, I have the following kind of "Hello World" C++ project going on here: http://cpp.sh/2ttqh
B4X:
// Example program Distance Between two points in 2D space.
#include <iostream>
#include <math.h>

long distance_between(long x1, long x2, long y1, long y2);

int main()
{
  // this is just an example
  std::cout << distance_between(123, 456, 789, 101) << "\n";
}

long distance_between(long x1, long x2, long y1, long y2)
{
    return sqrt( ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1)) );
}


...and I would like to have a head-to-head performance comparison with its B4A counterpart:
B4X:
Sub DistanceBetween(x1 as Long, x2 as Long, y1 as Long, y2 as Long) as Long
    Return Sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)))
End Sub

How to do it?
Well, i'm not too familiar with C++ but the first thing you need to do is convert this to an .so file!
 

walterf25

Expert
Licensed User
Longtime User
So, I have the following kind of "Hello World" C++ project going on here: http://cpp.sh/2ttqh
B4X:
// Example program Distance Between two points in 2D space.
#include <iostream>
#include <math.h>

long distance_between(long x1, long x2, long y1, long y2);

int main()
{
  // this is just an example
  std::cout << distance_between(123, 456, 789, 101) << "\n";
}

long distance_between(long x1, long x2, long y1, long y2)
{
    return sqrt( ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1)) );
}


...and I would like to have a head-to-head performance comparison with its B4A counterpart:
B4X:
Sub DistanceBetween(x1 as Long, x2 as Long, y1 as Long, y2 as Long) as Long
    Return Sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)))
End Sub

How to do it?
Check this http://stackoverflow.com/questions/9007693/call-c-library-from-java-in-android
 

MaFu

Well-Known Member
Licensed User
Longtime User
I think your sqrt example has not so much difference in runtime.
But for complex funktions the performance boost can be enormous.

I made a test with my MFLib (performance test of string compare function with wildcards).

Compare between:
B4A Regex function (search pattern = ʺ^.*best.*$")
MFLib.Compare() function (pure java and new NDK native version, search pattern = "*best*")

Short string (22 chars)
Regex: 0.0478 ms
MFLib.Compare (java): 0.0073 ms
MFLib.Compare (native): 0.0040 ms

Long string (162 chars)
Regex: 0.0510 ms
MFLib.Compare (java): 0.5028 ms
MFLib.Compare (native): 0.0161 ms
 

wonder

Expert
Licensed User
Longtime User
Hello again!

EDIT: I believe I've made some progress. See the post below.

I need your help...
I managed to create my collision detector in C++ and get the .so file with g++.exe.
The Java files were generated with Swig.exe.

cpppower.zip:
Capture.png


From this point on, I'm lost. I do not have Eclipse installed, so can anyone help me compile this lib?
The lib name should be "CppPower". Zip file attached.

Many thanks in advance. :)
 

Attachments

  • cpppower.zip
    14.1 KB · Views: 246
Last edited:

wonder

Expert
Licensed User
Longtime User
Alright, I think I made some progress and was able to do everything right in Eclipse, which I downloaded earlier today. Project file attached.

Can anyone help me wrap this Eclipse project into a B4A lib?
 

Attachments

  • lib_cpppower.zip
    26.1 KB · Views: 243

walterf25

Expert
Licensed User
Longtime User
Alright, I think I made some progress and was able to do everything right in Eclipse, which I downloaded earlier today. Project file attached.

Can anyone help me wrap this Eclipse project into a B4A lib?
Did you do this already? You must have already since i know you are beta testing a game!

Cheers,
Walter
 

wonder

Expert
Licensed User
Longtime User

walterf25

Expert
Licensed User
Longtime User
Yes I did, Walter, but I discarded Eclipse in favor of the SLC.

I'm using my Hadouken app for this purposes. :)
https://www.b4x.com/android/forum/threads/hadouken-b4a-native-library-generator-prototype.60050/
Great, maybe you can shed some light on an issue i'm currently having with an .so library, i'm writing a wrapper for a POS System with card reader and thermal printer, when i call a function that requires the .so file, i get an error telling me that i can't load the .so file and that is not an elf valid executable file, i did some research and using cygwin i tried to read the symbols in the file, that did not work it gave me the same error, telling me that it is not a elf format file, i tried to read two other files and i can read the symbols just fine, my first guess is that the .so file i'm trying to use is not of a compatible architecture or it was compiled for a different system, or the file is corrupted. Sorry i can't provide exact details about the error i get but i'm not home right now and forgot the exact wording of the error!

When i open the jar file of the wrapper, i can see the .so file in the lib folder.

Any thoughts, ideas?

Thanks,
Walter
 

JordiCP

Expert
Licensed User
Longtime User
Great, maybe you can shed some light on an issue i'm currently having with an .so library, i'm writing a wrapper for a POS System with card reader and thermal printer, when i call a function that requires the .so file, i get an error telling me that i can't load the .so file and that is not an elf valid executable file, i did some research and using cygwin i tried to read the symbols in the file, that did not work it gave me the same error, telling me that it is not a elf format file, i tried to read two other files and i can read the symbols just fine, my first guess is that the .so file i'm trying to use is not of a compatible architecture or it was compiled for a different system, or the file is corrupted. Sorry i can't provide exact details about the error i get but i'm not home right now and forgot the exact wording of the error!

When i open the jar file of the wrapper, i can see the .so file in the lib folder.

Any thoughts, ideas?

Thanks,
Walter
Strange... where did you get these so files?
 

walterf25

Expert
Licensed User
Longtime User
Well, I've just started taking my first steps in NDK/JNI, I don't know if I can be of much help.
You might be right, perhaps you got the wrong architecture. Do you have access to the native source code?
no worries Wonder, and no i don't have the source code, it came from my customer and he got it from the manufacturer!
 

walterf25

Expert
Licensed User
Longtime User
Strange... where did you get these so files?
Hi Jordi, it is strange, i got the so files from my client, and he got them from the device's manufacturer, i even tried changing the package name to the same package name in the example they provide, but even their example has issues, when i load it in eclipse the manifest.xml file shows strange characters, it doesn't seem to be an xml file.

Cheers,
Walter
 
Top