Android NDK에 벡터와 같은 C ++ 헤더를 포함 할 수 없습니다.
Android NDK 프로젝트 (최신 NDK r5b 사용)에 벡터와 같은 C ++ 클래스를 포함하려고하면 다음과 같은 오류가 발생합니다.
Compile++ thumb : test-libstl <= test-libstl.cpp /Users/nitrex88/Desktop/Programming/EclipseProjects/STLTest/jni/test-libstl.cpp:3:18: error: vector: No such file or directory
이 문제를 온라인으로보고 한 다른 사람들은 다음을 추가하여 성공을 주장했습니다.
APP_STL := stlport_static
Application.mk 파일에 추가합니다. 이 작업을 수행하고 APP_STL에 대해 가능한 다른 모든 값을 시도했습니다. 프로젝트를 정리하고, ndk-build를 정리하고, obj 및 libs 폴더를 삭제했지만 여전히 컴파일 할 때 벡터 클래스를 찾을 수 없습니다. 나는 몇 주 동안 (NDK r5가 나온 이후로)이 작업을 해 왔으며 누군가 조언이 있다면 정말 감사하겠습니다. 감사!
것이 가능하다. 다음은 단계별입니다.
에서 $ PROJECT_DIR / JNI / Application.mk :
APP_STL := stlport_static
stlport_shared를 사용해 보았지만 운이 없었습니다. libstdc ++와 동일합니다.
에서 $ PROJECT_DIR / JNI / Android.mk :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
여기에 특별한 것은 없지만 파일이 .cpp 인지 확인하십시오 .
에서 $ PROJECT_DIR / JNI / 안녕하세요 - jni.cpp :
#include <string.h>
#include <jni.h>
#include <android/log.h>
#include <iostream>
#include <vector>
#define LOG_TAG "hellojni"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
#ifdef __cplusplus
extern "C" {
#endif
// Comments omitted.
void
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
jobject thiz )
{
std::vector<std::string> vec;
// Go ahead and do some stuff with this vector of strings now.
}
#ifdef __cplusplus
}
#endif
여기서 나를 물린 유일한 것은 #ifdef __cplusplus입니다.
디렉토리를보십시오.
컴파일하려면 ndk-build clean && ndk-build
.
Android 스튜디오를 사용 중이고 ndk를 사용하여 컴파일 할 때 "error : vector : No such file or directory"(또는 기타 stl 관련 오류) 메시지가 계속 표시되는 경우이 방법이 도움이 될 수 있습니다.
프로젝트에서 모듈의 build.gradle 파일 (프로젝트의 build.grade가 아니라 모듈 용 파일)을 열고 defaultConfig의 ndk 요소 내에 'stl "stlport_shared"'를 추가합니다.
예 :
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.domain.app"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
ndk {
moduleName "myModuleName"
stl "stlport_shared"
}
}
}
I'm using Android Studio and as of 19th of January 2016 this did the trick for me. (This seems like something that changes every year or so)
Go to: app -> Gradle Scripts -> build.gradle (Module: app)
Then under model { ... android.ndk { ... and add a line: stl = "gnustl_shared"
Like this:
model {
...
android.ndk {
moduleName = "gl2jni"
cppFlags.add("-Werror")
ldLibs.addAll(["log", "GLESv2"])
stl = "gnustl_shared" // <-- this is the line that I added
}
...
}
Even Sebastian had given a good answer there 3 more years ago, I still would like to share a new experience here, in case you will face same problem as me in new ndk version.
I have compilation error such as:
fatal error: map: No such file or directory
fatal error: vector: No such file or directory
My environment is android-ndk-r9d and adt-bundle-linux-x86_64-20140702. I add Application.mk file in same jni folder and insert one (and only one) line:
APP_STL := stlport_static
But unfortunately, it doesn't solve my problem! I have to add these 3 lines into Android.mk to solve it:
ifndef NDK_ROOT
include external/stlport/libstlport.mk
endif
And I saw a good sharing from here that says "'stlport_shared' is preferred". So maybe it's a better solution to use stlport as a shared library instead of static. Just add the following lines into Android.mk and then no need to add file Application.mk.
ifndef NDK_ROOT
include external/stlport/libstlport.mk
endif
LOCAL_SHARED_LIBRARIES += libstlport
Hope this is helpful.
Let me add a little to Sebastian Roth's answer.
Your project can be compiled by using ndk-build
in the command line after adding the code Sebastian had posted. But as for me, there were syntax errors in Eclipse, and I didn't have code completion.
Note that your project must be converted to a C/C++ project.
How to convert a C/C++ project
To fix this issue right-click on your project, click Properties
Choose C/C++ General -> Paths and Symbols and include the ${ANDROID_NDK}/sources/cxx-stl/stlport/stlport
to Include directories
Click Yes when a dialog shows up.
Before
After
Update #1
GNU C. Add directories, rebuild. There won't be any errors in C source files
GNU C++. Add directories, rebuild. There won't be any errors in CPP source files.
If you are using ndk r10c or later, simply add APP_STL=c++_static to Application.mk
This is what caused the problem in my case (CMakeLists.txt
):
set (CMAKE_CXX_FLAGS "...some flags...")
It makes invisible all earlier defined include directories. After removing / refactoring this line everything works fine.
In android NDK go to android-ndk-r9b>/sources/cxx-stl/gnu-libstdc++/4.X/include in linux machines
I've found solution from the below link http://osdir.com/ml/android-ndk/2011-09/msg00336.html
참고URL : https://stackoverflow.com/questions/4893403/cant-include-c-headers-like-vector-in-android-ndk
'development' 카테고리의 다른 글
Xcode에서 기본 헤더 주석 라이센스 변경 (0) | 2020.09.24 |
---|---|
IN 절의 매개 변수 목록이있는 PreparedStatement (0) | 2020.09.24 |
문자열이 다른 문자열로 시작하는지 또는 끝나는 지 테스트 (0) | 2020.09.24 |
DTD에서 PCDATA와 CDATA의 차이점 (0) | 2020.09.24 |
WPF 사용자 정의 컨트롤에서 가져온 리소스와 로컬 리소스를 결합하는 방법 (0) | 2020.09.24 |