Hi All,
I am relatively new to Android Studio 2.2, and I am sure that I am doing something stupid here but after pouring through days of documentation I am still at a lost as to how to solve my problem below.
I fount the bundled cmake feature great and would really like to use it in my project, however, I have run into problems and have been struggling for over a week to try to get cmake to find the boost system library that is used by the asio header file in boost. My CMakeLists.txt is as follows:
**************************************************************************************************************************************************
# Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower.
cmake_minimum_required(VERSION 3.4.1)
include_directories(/usr/local/Cellar/jpeg/8d/include)
add_library(tiff_lib SHARED IMPORTED)
set_target_properties(tiff_lib PROPERTIES IMPORTED_LOCATION
/usr/local/Cellar/libtiff/4.0.6/lib/libtiff.a)
include_directories(/usr/local/Cellar/libpng/1.6.21/include)
add_library(png_lib SHARED IMPORTED)
set_target_properties(png_lib PROPERTIES IMPORTED_LOCATION
/usr/local/Cellar/libpng/1.6.21/lib/libpng.a)
include_directories(/usr/local/Cellar/libtiff/4.0.6/include)
add_library(jpeg_lib SHARED IMPORTED)
set_target_properties(jpeg_lib PROPERTIES IMPORTED_LOCATION
/usr/local/Cellar/jpeg/8d/lib/libjpeg.a)
set (BOOST_ROOT "/usr/local/Cellar/boost/1.62.0")
set (Boost_INCLUDE_DIR "/usr/local/Cellar/boost/1.62.0/include")
set (BOOST_LIBRARYDIR "/usr/local/Cellar/boost/1.62.0/lib")
set (Boost_USE_STATIC_LIBS ON)
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
find_package(Boost 1.62.0 EXACT COMPONENTS
date_time
filesystem
regex
serialization
system
timer)
include_directories(/Users/robertblack/Desktop/Member_Aandroid_1/app/src/main/cpp/include)
add_subdirectory(src/main/cpp/utilities)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
# Associated headers in the same location as their source
# file are automatically included.
src/main/cpp/native-lib.cpp)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because system libraries are included in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
mathUtilities
stringUtilites
# Links the target library to the log library
# included in the NDK.
${log-lib} )
**************************************************************************************************************************************************
If I include the Boost/asio in my header or cpp file I get the following error messages as seen below:
**************************************************************************************************************************************************
Error:FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing '/Applications/android-sdk-macosx/cmake/3.6.3155560/bin/cmake' with arguments {--build /Users/robertblack/Desktop/Member_Aandroid_1/app/.externalNativeBuild/cmake/debug/mips64 --target workerThreadImp}
[1/2] Building CXX object src/main/cpp/utilities/Assets/CMakeFiles/workerThreadImp.dir/WorkerThreadImp.cpp.o
[2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/mips64/libworkerThreadImp.so
FAILED: : && /Applications/android-sdk-macosx/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ -target mips64el-none-linux-android -gcc-toolchain /Applications/android-sdk-macosx/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/darwin-x86_64 --sysroot=/Applications/android-sdk-macosx/ndk-bundle/platforms/android-21/arch-mips64 -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -std=c++11 -frtti -fexceptions -DBOOST_SYSTEM_NO_DEPRECATED -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libworkerThreadImp.so -o ../../../../build/intermediates/cmake/debug/obj/mips64/libworkerThreadImp.so src/main/cpp/utilities/Assets/CMakeFiles/workerThreadImp.dir/WorkerThreadImp.cpp.o -lm "/Applications/android-sdk-macosx/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/mips64/libgnustl_static.a" && :
src/main/cpp/utilities/Assets/CMakeFiles/workerThreadImp.dir/WorkerThreadImp.cpp.o: In function `boost::asio::error::get_system_category()':
/usr/local/Cellar/boost/1.62.0/include/boost/asio/error.hpp:230: undefined reference to `boost::system::system_category()'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
**************************************************************************************************************************************************
If anyone can help, it would be very much appreciated.