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

working static library gmath with gpower method #1

Merged
merged 1 commit into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

cmake_minimum_required(VERSION 3.4.1)


# configure import libs
set(distribution_DIR ${CMAKE_SOURCE_DIR}/../distribution)

add_library(lib_gmath STATIC IMPORTED)
set_target_properties(lib_gmath PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/gmath/lib/${ANDROID_ABI}/libgmath.a)

# 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 them for you.
Expand Down Expand Up @@ -32,13 +40,15 @@ find_library( # Sets the name of the path variable.
# you want CMake to locate.
log )

target_include_directories(native-lib PRIVATE
${distribution_DIR}/gmath/include)


# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
native-lib

# Links the target library to the log library
# included in the NDK.
lib_gmath
${log-lib} )
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
arguments '-DANDROID_STL=c++_static'
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/cpp/native-lib.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <jni.h>
#include <string>
#include <gmath.h>

extern "C"
JNIEXPORT jstring
Expand All @@ -8,6 +9,7 @@ JNICALL
Java_farzi_labs_helloworldexternallibs_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
std::string result = std::to_string(gpower(4));
std::string hello = "The square of 4 is : "+result;
return env->NewStringUTF(hello.c_str());
}
27 changes: 27 additions & 0 deletions distribution/gmath/include/gmath.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef __POWER_HPP__
#define __POWER_HPP__
/*
* return pow(2, n)
*/
#ifdef __cplusplus
extern "C"
#endif // __cplusplus
unsigned gpower(unsigned n);

#endif //__POWER_HPP__
Binary file added distribution/gmath/lib/arm64-v8a/libgmath.a
Binary file not shown.
Binary file added distribution/gmath/lib/armeabi-v7a/libgmath.a
Binary file not shown.
Binary file added distribution/gmath/lib/x86/libgmath.a
Binary file not shown.
Binary file added distribution/gmath/lib/x86_64/libgmath.a
Binary file not shown.