Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile libminimapshared.so for x86 for Unit Test #161

Open
cepages opened this issue Apr 24, 2020 · 10 comments
Open

Compile libminimapshared.so for x86 for Unit Test #161

cepages opened this issue Apr 24, 2020 · 10 comments
Labels
Feature Request New feature or request

Comments

@cepages
Copy link

cepages commented Apr 24, 2020

Is your feature request related to a problem? Please describe.

Using unit test when using libminimapshared.so

Describe the solution you'd like

I'm using your app but only with minimap in Android, I have to say you've done a great job!.

My project has some unit test and instrumented test.

My instrumented test are passing with no problems but unit test are complaining in the building process because libminimapshared.so hasn't been built for x86.

I've achieved to create libminimapshared.so from the minimap source code (https://github.com/lh3/minimap2).

Unfortunately when I build my project for unit test, it seems it doesn't recogniseinit_minimap2

/../app/src/main/cpp/native-lib.cpp:120: error: undefined reference to 'init_minimap2'

Could you point if you did anything extra to create libminimapshared.so?

Thanks

@cepages cepages added the Feature Request New feature or request label Apr 24, 2020
@SanojPunchihewa
Copy link
Owner

Yes, you need to rename the main function to init_minimap2 in the source code of minimap2. You can use this modified minimap2 code which we used to build the shared library. You can build it using CMake with this script

If this doesn't solve your issue, please let me know

@cepages
Copy link
Author

cepages commented Apr 24, 2020

Thanks for your help.

I changed the cmakerun.sh file to get the shared object for x86

# for architecture x86
 cmake .. -DDEPLOY_PLATFORM=x86
 make -j 8

But I think XCode hasn't got the support enabled for NEON:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.1/include/arm_neon.h:28:2: error: "NEON support not enabled"
#error "NEON support not enabled"

I think you are running on Linux so you are not using XCode :S , I will try to investigate it although any advice is welcome :)

Thanks

@hiruna72
Copy link
Collaborator

Yes we compiled all the libraries on Ubuntu terminal and copied them to Android Studio later. We have not tried compiling minimap2 on iOS.

Can you try to compile on command line?

I thought x86 uses SSE not NEON.

You can also try to give a CMake option, e.g., we use -DANDROID_ARM_NEON=ON to cross-compile for Android.

Let us know what happened :)

@SanojPunchihewa
Copy link
Owner

Since we built minimap2 for arm devices we compiled NEON related source files and included some headers. You can see them in the original Makefile also. If you want to use our CMake then you have to make some changes to it.
Since you were able to build libminimapshared.so from the minimap source code, I recommend you to manually rename the main function to init_minimap2 in the source code. Also, make sure you have the header file in cpp directory and included it in native-lib.cpp

@cepages
Copy link
Author

cepages commented Apr 27, 2020

@hiruna72 I'm trying to build for x86 for my test in Android (iOS will come later :) )

I commented the armeabi-V7a and the arm64-v8a and uncommented the x86 so the code with the option -DANDROID_ARM_NEON=ON is commented:

# for architecture x86
 cmake .. -DDEPLOY_PLATFORM=x86
 make -j 8

# # for architecture armeabi-V7a
# cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE:STRING=$toolchain_file -DANDROID_PLATFORM=android-21 -DDEPLOY_PLATFORM:STRING="armeabi-v7a" -DANDROID_ABI="armeabi-v7a" -DANDROID_ARM_NEON=ON

# # for architecture arm64-v8a
# cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE:STRING=$toolchain_file -DANDROID_PLATFORM=android-23 -DDEPLOY_PLATFORM:STRING="arm64-v8a" -DANDROID_ABI="arm64-v8a" -DANDROID_ARM_NEON=ON

@cepages
Copy link
Author

cepages commented Apr 27, 2020

@SanojPunchihewa so do you use NEON source files for x86 too?

I follow your steps, replacing the main to init_minimap2 and creating the libminimapshared.so again. It still complains about the same:

error: undefined reference to 'init_minimap2'

It may be how I create libminimapshared.so. If I get the symbols using nm -g libminimapshared.so I don't get init_minimap2

I'm creating the libminimapshared.so adding the following rule in the make file:

libminimapshared.so: $(OBJS)
		$(CC) -shared $^ $(LIBS) -o $@

@hiruna72
Copy link
Collaborator

I made some changes to the CMakeLists.txt file. Can you checkout here and run the cmakerun.sh file? I got it working.

To make sure the shared library works, I also added an example code.
You will find the executable built from the example code inside build directory along with the shared library.

@cepages
Copy link
Author

cepages commented Apr 28, 2020

Thanks a lot @hiruna72

I had to run the cmakerun.sh in a linux docker image because in mac it doesn't generate the libminimapshared.so

After running cmakerun.sh in the linux docker image, I've got the libminimapshared.so , I've checked the symbol and it contains the init_minimap2 symbol.

But in Android studio I'm still getting the same error, no idea why.

I will keep trying to investigate, maybe something is cached.

Thanks a lot for your help.

@hiruna72
Copy link
Collaborator

You are welcome, great to hear that !

We also faced similar undefined reference issues at different points along the process.

In Android, the reason could be, the C/CPP name mangling issue.

Can you try after decorating the interface.h file like this? Make sure to rename the file to interface_minimap.h.

@cepages
Copy link
Author

cepages commented Apr 28, 2020

Yeah, I already had that interface in the cpp folder with that content and that name.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants