compile a simple cpp file take 20+ seconds
hello.cpp:
#include <jni.h>
#include <string>
extern "C"
JNIEXPORT jstring JNICALL
Java_com_example_cpptest_slice_MainAbilitySlice_stringFromJNI(JNIEnv* env, jobject obj) {
std::string hello = "Hello from JNI C++ codes";
int len = hello.size();
jchar res[len];
for (int i = 0; i < len; i++) {
res[i] = (jchar)hello[i];
}
return env->NewString(res, len);
}
CMakeList.txt:
# the minimum version of CMake.
cmake_minimum_required(VERSION 3.4.1)
project(cpptest)
add_library(hello SHARED hello.cpp)
target_link_libraries(hello)
command:
[cmake] D:\HarmonySdk\3.0.1.93\native\3.0.1.93\build-tools\cmake\bin\cmake.exe -HC:\Users\Administrator\DevEcoStudioProjects\cpptest\entry\src\main\cpp\ -BC:\Users\Administrator\DevEcoStudioProjects\cpptest\entry\.cxx\debug\arm64-v8a -DOHOS_ARCH=arm64-v8a -DCMAKE_L
IBRARY_OUTPUT_DIRECTORY=C:\Users\Administrator\DevEcoStudioProjects\cpptest\entry\build\intermediates\cmake\debug\obj\arm64-v8a -DCMAKE_BUILD_TYPE=Debug -DOHOS_SDK_NATIVE=D:\HarmonySdk\3.0.1.93\native\3.0.1.93 -DCMAKE_SYSTEM_NAME=OHOS -DCMAKE_OHOS_ARCH_ABI=arm64-v8
a -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=D:\HarmonySdk\3.0.1.93\native\3.0.1.93\build\cmake\ohos.toolchain.cmake -G Ninja -DCMAKE_MAKE_PROGRAM=D:\HarmonySdk\3.0.1.93\native\3.0.1.93\build-tools\cmake\bin\ninja.exe
info:
-- The CXX compiler identification is Clang 9.0.0
System is unknown to cmake, create:
Platform/OHOS to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting C compiler ABI info
System is unknown to cmake, create:
Platform/OHOS to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/HarmonySdk/3.0.1.93/native/3.0.1.93/llvm/bin/clang.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
System is unknown to cmake, create:
Platform/OHOS to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/HarmonySdk/3.0.1.93/native/3.0.1.93/llvm/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Administrator/DevEcoStudioProjects/cpptest/entry/.cxx/debug/arm64-v8a
it will take 20 + seconds
Edited by Brad King