Linking on Android with mk file

Aug 7, 2015 at 9:20 PM
Edited Aug 7, 2015 at 9:32 PM
I've having trouble linking cpprest in my android application. I get the following errors:

E:\stgatesdev\packages\boost.1.55.0.16\build\native....\lib\native\include\boost/system/error_code.hpp:222: error: undefined reference to 'boost::system::generic_category()'
E:\stgatesdev\packages\boost.1.55.0.16\build\native....\lib\native\include\boost/system/error_code.hpp:223: error: undefined reference to 'boost::system::generic_category()'
E:\stgatesdev\packages\boost.1.55.0.16\build\native....\lib\native\include\boost/asio/ssl/detail/impl/openssl_init.ipp:39: error: undefined reference to 'SSL_library_init'
E:\stgatesdev\packages\boost.1.55.0.16\build\native....\lib\native\include\boost/asio/ssl/detail/impl/openssl_init.ipp:40: error: undefined reference to 'SSL_load_error_strings'

Among others. It looks like the symbols to the cpprest dependencies are not being resolved.

I have this in my application's mk file:
LOCAL_STATIC_LIBRARIES := libcrypto
LOCAL_STATIC_LIBRARIES += libssl
LOCAL_STATIC_LIBRARIES += libboost_atomic-clang-mt-1_55
LOCAL_STATIC_LIBRARIES += libboost_chrono-clang-mt-1_55
LOCAL_STATIC_LIBRARIES += libboost_date_time-clang-mt-1_55
LOCAL_STATIC_LIBRARIES += libboost_filesystem-clang-mt-1_55
LOCAL_STATIC_LIBRARIES += libboost_system-clang-mt-1_55
LOCAL_STATIC_LIBRARIES += libboost_thread-clang-mt-1_55
LOCAL_STATIC_LIBRARIES += libcpprest 

include $(BUILD_SHARED_LIBRARY)

$(call import-module,casablanca/$(TARGET_ARCH_ABI))
and the following in the cpprest mk file:
LOCAL_PATH:= $(call my-dir)

#static version of openssl crypto
include $(CLEAR_VARS)
LOCAL_MODULE := libcrypto
LOCAL_SRC_FILES := openssl/libcrypto-clang-1_0_1h.a
include $(PREBUILT_STATIC_LIBRARY)

#static version of openssl ssl
include $(CLEAR_VARS)
LOCAL_MODULE := libssl
LOCAL_SRC_FILES := openssl/libssl-clang-1_0_1h.a
include $(PREBUILT_STATIC_LIBRARY)

#static version of libiconv
#include $(CLEAR_VARS)
#LOCAL_MODULE := libiconv
#LOCAL_SRC_FILES := iconv/libiconv.a
#include $(PREBUILT_STATIC_LIBRARY)

#static version of libboost atomic
include $(CLEAR_VARS)
LOCAL_MODULE := libboost_atomic-clang-mt-1_55
LOCAL_SRC_FILES := boost/libboost_atomic-clang-mt-1_55.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include/boost
include $(PREBUILT_STATIC_LIBRARY)

#static version of libboost chrono
include $(CLEAR_VARS)
LOCAL_MODULE := libboost_chrono-clang-mt-1_55
LOCAL_SRC_FILES := boost/libboost_chrono-clang-mt-1_55.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include/boost
include $(PREBUILT_STATIC_LIBRARY)

#static version of libboost date time
include $(CLEAR_VARS)
LOCAL_MODULE := libboost_date_time-clang-mt-1_55
LOCAL_SRC_FILES := boost/libboost_date_time-clang-mt-1_55.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include/boost
include $(PREBUILT_STATIC_LIBRARY)

#static version of libboost file system
include $(CLEAR_VARS)
LOCAL_MODULE := libboost_filesystem-clang-mt-1_55
LOCAL_SRC_FILES := boost/libboost_filesystem-clang-mt-1_55.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include/boost
include $(PREBUILT_STATIC_LIBRARY)

#static version of libboost locale
#include $(CLEAR_VARS)
#LOCAL_MODULE := libboost_locale-clang-mt-1_55
#LOCAL_SRC_FILES := boost/libboost_locale-clang-mt-1_55.a
#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include/boost
#include $(PREBUILT_STATIC_LIBRARY)

#static version of libboost random
#include $(CLEAR_VARS)
#LOCAL_MODULE := libboost_random-clang-mt-1_55
#LOCAL_SRC_FILES := boost/libboost_random-clang-mt-1_55.a
#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include/boost
#include $(PREBUILT_STATIC_LIBRARY)

#static version of libboost system
include $(CLEAR_VARS)
LOCAL_MODULE := libboost_system-clang-mt-1_55
LOCAL_SRC_FILES := boost/libboost_system-clang-mt-1_55.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include/boost
include $(PREBUILT_STATIC_LIBRARY)

#static version of libboost thread
include $(CLEAR_VARS)
LOCAL_MODULE := libboost_thread-clang-mt-1_55
LOCAL_SRC_FILES := boost/libboost_thread-clang-mt-1_55.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include/boost
include $(PREBUILT_STATIC_LIBRARY)

#static version of cpprest
include $(CLEAR_VARS)
LOCAL_MODULE := libcpprest
LOCAL_SRC_FILES := cpprest/cpprest140_android_2_6.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include/
include $(PREBUILT_STATIC_LIBRARY)
The casablanca module seems to be loaded correctly (ie the paths and src files produce no errors mentioning file paths) and I can compile. Its not until the linking process that I get these errors. Anyone have ideas?

Edit: I should add that the binaries i'm using in the above example were obtained from NuGet. However, binaries produced by building on a Linux box result in the same errors.
Coordinator
Aug 12, 2015 at 8:37 PM
Can you build in verbose mode and post the exact command lines used to build? I suspect this is possibly an ordering issue on the link line.
Aug 19, 2015 at 3:14 AM
I managed to link using LOCAL_WHOLE_STATIC_LIBRARIES in the mean time. I will look into the link ordering tomorrow.
Marked as answer by roschuma on 8/25/2015 at 3:06 PM