I want to use libjpeg-turbo (exactly only libjpeg) in my Android NDK project. I can't find how to completely add the library to my project.
- Firstly, I build it by using
BUILDING.md(as fourANDROID_ABI:arm64-v8a,armeabi-v7a,x86,x86-64). - Secondly, I prepare in my project
src/main/cppfolderlibjpegand put inANDROID_ABIfolders libjpeg.a static libraries.
Next I add to CMakeLists.txt:
add_library( libjpeg STATIC IMPORTED )
set_target_properties( libjpeg
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libjpeg/${ANDROID_ABI}/libjpeg.a )
# and
target_link_libraries(
native-lib
libjpeg
${log-lib})
Below is my whole CMakeLists.txt:
cmake_minimum_required(VERSION 3.4.1)
add_library( libjpeg STATIC IMPORTED )
set_target_properties( libjpeg
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libjpeg/${ANDROID_ABI}/libjpeg.a )
include_directories(src/main/cpp/rapidjson/)
include_directories(src/main/cpp/Eigen)
file(GLOB CPP_FILES "src/main/cpp/*.cpp")
add_library(
native-lib
SHARED
native-lib.cpp
common.cpp
archive.cpp
crc32.cpp
image.cpp
read_manifest.cpp
sensors.cpp
thumbnail.cpp
upf.cpp
upf-toolkit.cpp
write_manifest.cpp
write_upf.cpp
)
find_library(log-lib log)
target_link_libraries(native-lib libjpeg ${log-lib})
I have no building errors, but I can't include the libjpeg header in my cpp file.
You receive the compile error because your CMake code doesn't specify the location of
libjpegheader files. You can specify the directory containing thelibjpegheaders by setting theINTERFACE_INCLUDE_DIRECTORIESproperty for the importedlibjpegtarget.Note: You may have to modify the path to match where these headers reside on your machine.
With a couple other nit-picky notes (unrelated to the error), your updated CMake file may look something like this: