shared library, loads ok but not operable

Skip to first unread message

Dorion Liston

Mar 2, 2023, 9:00:48 PMMar 2
to android-ndk
Hello Android NDK Peers,

I'm hoping the accumulated experience on this list can help me troubleshoot this issue.  I used NDK to build a shared library containing some native C++ code and a nice prebuilt shared library called nlopt that I use for mathematical optimizations, basically a few simple fits.     Both of these seem to build cleanly using the file coped below the message.  The nlopt library was built separately using cmake and the android cmake toolchain, also built cleanly.  

The libraries build without any errors, and the native C++ code runs as expected on PC when it calls the nlopt library.  On an Android device (Magic Leap 2), however, this optimization function does not fail with an error ... but seems not to run at all on the device. The function instead seems to return the exact same parameters I passed in as a starting point to initialize the fit.   Any thoughts on what could be going wrong here?  

Thanks, everybody, I really appreciate any suggestions from the group. 




LOCAL_PATH := $(call my-dir)

# 230113, include nlopt library for optimization

include $(CLEAR_VARS) # points to a special GNU makefile
LOCAL_MODULE := nlopt # 1) give the module a name; it need not match the prebuilt library
LOCAL_SRC_FILES := /home/neurofit/projects/android/nlopt/nlopt-2.7.1/build/lib/
LOCAL_EXPORT_C_INCLUDES := /usr/local/include

SRC_DIR = /home/neurofit/projects/cpp.oculometrics/cpp/source

include $(CLEAR_VARS) # points to a special GNU makefile

#$(info $(LOCAL_C_INCLUDES))
LOCAL_EXPORT_C_INCLUDE_DIRS := /usr/local/include # nlopt.hpp

LOCAL_SRC_FILES := $(wildcard $(SRC_DIR)/*.cpp)
LOCAL_SRC_FILES += ./cpp/cobra_api.cpp
#$(info $(LOCAL_SRC_FILES))
LOCAL_CPP_FEATURES += exceptions # 230120
LOCAL_SHARED_LIBRARIES := nlopt # name matches LOCAL_MODULE above

James Farrell

Mar 3, 2023, 3:37:39 PMMar 3
I haven't done a full investigation, so I'm not sure what's going on here, but I wanted to point you to a couple of our NDK samples that may be helpful.

Also, take a look at Prefab and, which gives you a nice, standard way to package nlopt into an AAR that you can depend on.

-- James

You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages