Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake on android find_library fail to find with custom path

I failed to find_library with cmake/android, so I wrote this simple test.

find_library(log-lib log
  PATHS /Users/sam/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm/usr/lib
  NO_DEFAULT_PATH)

It's Ok. Then I copy that lib directory to another location.

find_library(log-lib log
  PATHS /Users/sam/tmp/lib
  NO_DEFAULT_PATH)

Fail! I am pretty sure that I have copied the whole lib directory.

Any ideas? Thanks in advance.

like image 958
Sun Yi-Ming Avatar asked Sep 05 '17 12:09

Sun Yi-Ming


1 Answers

Since you are cross-compiling, you must tell CMake that it is allowed to use a library elsewhere than specified by the toolchain (in your case, elsewhere than the Android SDK directory).

To do so, you can add this:

set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)

(in your case, only the first one is relevant)

More information here.

like image 64
oLen Avatar answered Oct 22 '22 21:10

oLen