반응형

android 프로그램을 개발하다 보면, 종종 C++ 또는 C로 작성된 코드를 사용해야 하거나, xxx.a 또는 yyy.so 와 같은 static library 또는 shared library 를 사용해야 하는 상황들이 발생합니다.

 

static library 

static library는 소스(source) 빌드시  링킹 시점에 심볼(symbol)이 연결됩니다.

주로  xxx.a 처럼 .a 확장자를 사용합니다.

shared library 

shared library는 런타임(runtime, 실행시점)때 필요시점에 library를 로딩해서 symbol이 연결됩니다.

주로 .so 또는 .dll 확장자로 사용됩니다.

 

이런 경우를 위해서 java에서는 JNI(java native interface) 를 제공하고 있습니다.

 

Android Studio 에서 기본적으로 CMake와 make file 을 통해서 구현이 가능합니다.

 

    static {
        System.loadLibrary("native-lib");
    }
    private native String stringFromJNI();

 

extern "C" JNIEXPORT jstring JNICALL
Java_com_my_package_JniClass_stringFromJNI(
        JNIEnv* env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}

 

그러나 android 가 vm 위에서 동작하는 것과 달리 native code는 platform에 종속성(dependency)를 가지게 되니, 빌드 환경이나 플랫폼에 영향을 받게 됩니다.

 

 

C++ 관련 link error

ld: error: undefined symbol: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
  >>> referenced by string:1078 (external/libcxx/include/string:1078)

 

때문에 ndk build 시 에러가 발생하는 경우들이 나옵니다.

android jni 의 native build error 는 주로 아래 so들 때문에 발생하는 경우들이 많습니다.

c++관련 toolchain file 인데,  android 에서는 어떤 이유에선지 해당 so file들을 제공하지 않습니다.

build 시 또는 runtime에 에러가 발생하게 됩니다.

 

libc++.so, libbase.so, libcutils.so

 

https://developer.android.com/about/versions/nougat/android-7.0-changes?hl=ko 

 

Android 7.0 동작 변경 사항  |  Android 개발자  |  Android Developers

Along with new features and capabilities, Android 7.0 includes a variety of system and API behavior changes. This document highlights some of the key changes that you should understand and account for in your apps. If you have previously published an …

developer.android.com

 

만들고자 하는 native lib을 static으로 만들면 build는 해결할 수 있지만, java에서 c++ native  symbol link 과정은 컴파일(compile)시에 결정되는 것이 아니라 런타임(runtime linking 또는 dynamic linking )을 하기 때문에 so file을 사용해야 합니다.

 

즉 해결 방법은, libc++.so, libbase.so, libcutils.so 파일들을 모두 application library로 포함 시켜야 합니다.

 

 

 

'Android, Java,Kotlin' 카테고리의 다른 글

[Copy&Paste]String 다루기  (0) 2020.11.11
[Copy&Paste] Array를 List로 바꾸기  (0) 2020.11.04
[Android] JavaDoc 사용법 링크.  (0) 2020.10.28
반응형

 

 

 

 

 

 

 

 

#완전 수동 블럭 코딩!!  #복붙 코딩!!

Ubunut 14.04에서 Perforce를 설치하고 실행하려는데 다음과 같은 에러가 발생했습니다.

 

https://www.perforce.com/downloads/helix-visual-client-p4v

 

Helix Visual Client (P4V) | Perforce

Helix Visual Client (P4V) is a desktop app that provides access to versioned files in Helix Core through a graphical interface. It includes tools for merging and visualizing code evolution. Powerful Access to Your Versioned Files With P4V, it’s easy to c

www.perforce.com

 

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found. 
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. 

Available platform plugins are: minimal, offscreen, vnc, xcb. 

Aborted (core dumped) 

 

xcb 관련 에러로 보여서 찾아보니 libxcb-xinerama0 를 설치하면 해결이 된다고 해서 설치 해봤습니다.

 

apt install libxcb-xinerama0

 

 

 

p4화면이 잘 나오네요.

 

그런데 주소 입력창에서 다음과 같은 에러가 발생했습니다.

/p4v.bin: relocation error: ..../p4v/lib/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so: 
symbol xkb_compose_table_new_from_locale, version V_0.5.0 not defined in file libxkbcommon.so.0 with link time reference

 

 

p4v 2020.03p4v-2020.3.2048092 의 경우에 발생되는 문제로 보입니다.

 

낮은 버전을 사용하는 경우 문제가 발생하지 않네요.

저는 p4v-2020.1.1966006 이 버전으로 했을때 문제 없이 동작 했습니다.

 

 

반응형

Conda 설치 

 

여기에서 각 OS에 맞는 anaconda를 설치하세요.

https://www.anaconda.com/distribution/

 

Anaconda Python/R Distribution - Free Download

Anaconda Distribution is the world's most popular Python data science platform. Download the free version to access over 1500 data science packages and manage libraries and dependencies with Conda.

www.anaconda.com

 

설치후 shell을 실행하면, (base) 로 conda가 활성화 되어있습니다.

이를 제거 하려면,

$ conda config --set auto_activate_base false

이렇게 설정 하시면 됩니다.

 

사용 방법

 

conda 설치 후에 가상 환경을 만듭니다.

 

$ conda create -n torch python=3.6  # torch라는 가상 환경을 만듭니다.

 

(torch) $ conda activate torch  # 가상환경 torch를 activate 시킵니다.

 

(torch) $ conda deactivate # 가상환경 torch를 deactivate 시킵니다.

 

 

 

 

 

 

[출처] [Ubuntu18.04 환경설정] Anaconda3 설치 및 가상환경 생성|작성자 DL연구생

 

 

Trouble shooting #1

 

 

conda 설치할때, 방화벽이 있거나 보안이 철저한 환경에서 셋업을 할때는 아래와 같은 설정을 해줘야 합니다.

 

이런 정보들 찾아서 시도해보고 다시 정리하고 하는 것은 정말 많은 시간을 낭비하게 되네요.

회사들 마다 보안 환경들이 모두 다르기 때문에 더더욱 시간 허비가 심하죠.

 

그래서 도움이 될까 해서 정리 했습니다.

 

 

SSL 또는 Proxy error

ConnectTimeout(MaxRetryError("HTTPSConnectionPool(host='repo.anaconda.com', port=443): Max retries exceeded with url: /pkgs/main/linux-64/current_repodata.json (Caused by ConnectTimeoutError(, 'Connection to repo.anaconda.com timed out. (connect timeout=9.15)'))")) 

 

 

프록시 설정을 .condarc 파일 에서 하기

ssl_verify: <my crt file>.crt

proxy_servers:
      http: http://<proxy server url : port> 
      https: https://<proxy server url : port> 

 

 

 

 

다른 방법

cert file 설치을 pip 의 certi file 로 설정하는 방법

 

pip config set global.cert path/to/ca-bundle.crt
pip config list conda config --set ssl_verify path/to/ca-bundle.crt
conda config --show ssl_verify# Bonus while we are here...
git config --global http.sslVerify true
git config --global http.sslCAInfo path/to/ca-bundle.crt

 

 

패키기 설치(Package install)

 

conda install [pkgname]

 

 

 

[참고]

conda configuration guide

https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#config-proxy

 

 

 

 

 

 

 

반응형

undefined symbol error는 흔히 어떤 함수를 사용하려고 하는데, 

실제 함수의 구현체가 없는 경우에 linking 하는 과정에서 발생하는 에러입니다.


개발자가 보기에는 에러가 발생안해야 하는데, 이상하게 발생한다고 느껴지는 경우들이 종종 있습니다.


몇가지 경우를 살펴봅시다.



1) header file에만 해당 함수가 정의되어있고 구현부가 없는 경우,

만약 바이너리(binary)로 되어있는 lib과 h 파일을 사용하는 경우, lib안에 해당 함수가 구현이 안되어있을 것입니다.


2) binary에도 구현이 되어있는데, 안되는 경우,

binary 가 so또는 dll 과 같이 shared lib으로 만들어졌을때에, 해당 함수가 export안되어 있어서, 외부에서는 사용할 수 없는 경우입니다.


3) 구현도 되어있고 export 되어있는 경우,

c 로 작성된 함수여서 cpp 파일에서 사용하려고 할때 naming 이 mangling 되어 문제가 발생할 수 있습니다.

ex) void abcd(int a) 라는 함수가 c로 작성된 API명은  _abcd 라는 symbol을 제공하는데,

cpp에서 include 해서 사용하려다 보니 _abcdi 와 같은 전혀 다른 이름으로 호출이 되어 발생할 수 있습니다.

extern "C" 로 해결이 가능한 부분입니다.


원인은 대부분 이 3가지 경우들에 포함될것 입니다.


이 와 관련 내용으로 아래 링크에 따로 정리되어 있습니다.


C++ 상에서 발생하는 name mangling 에 관한 내용


 

<참고>

undefined symbol error와 관련해서 색다른 사용법과 회피 방법이 있습니다.


프로젝트를 진행하다보면,

build 환경에는 symbol이 없고, 실행 환경에만 library가 있다거나 symbol이 있다거나 하는 경우들이 발생합니다.

이럴 경우, build 시점에 undefined symbol error들이 발생하는데,

이를 회피 하고자 할때 사용하는 방법이

link option에서 undefined symbol을 무시하는 방법이 있습니다.

 

linux 의 ld 옵션  https://linux.die.net/man/1/ld

 

ld 옵션 중에  --allow-shlib-undefined 가 있습니다.

 


link option에  --allow-shlib-undefined 를 주게 되면,  undefined symbol이 발생하더라도,  build error 를 발생시키지 않고 

바이너리를 만들어내게 됩니다.



부득이한 경우에 회피할 수 있는 방법이긴 하나, 전체적으로 보면 이는 좋은 방법은 아닙니다.


이 옵션이 켜진 상태로 프로젝트를 진행하다보면, 실제로 함수구현이 빠진 부분을 발견하지 못하고 넘어갈 수도 있습니다.


그렇게 되면 원인을 찾는데 매우 큰 시간이 들게 됩니다.



'Linux' 카테고리의 다른 글

relro,Stack Canary 방어  (0) 2018.06.05
tput: no value for $term 에러 발생  (0) 2017.11.21
open 되어있는 fd 확인하기.  (0) 2017.03.03
프로세스의 메모리 사용량  (0) 2017.01.11
rpm 사용법  (0) 2014.02.13

+ Recent posts