Skip to main content

Linking and pkg-config

Map each SPECS NDK header to its CMake target and link flag, and use pkg-config against the target sysroot.

Each SPECS NDK API has its own shared library, except SpecsFs, which is header-only on the device. This page maps every header to its CMake target and link flag, and shows how to find other sysroot libraries through pkg-config.

Library linking reference

Link only the SPECS libraries your code directly uses. The following table maps each API header to its library.

HeadersCMake targetLink flag
SpecsPlayer.hspecs_player-lspecs_player
SpecsMedia.h, SpecsMediaCodec.h, SpecsMediaExtractor.h, SpecsMediaFormat.h, SpecsMediaPresenter.h, SpecsMediaBuffer.h, SpecsMediaGLTexture.h, SpecsRecorder.h, SpecsCapture.hspecs_media-lspecs_media
SpecsAudioPlayback.hspecs_audio_playback-lspecs_audio_playback
SpecsAudioRecord.hspecs_audio_record-lspecs_audio_record
SpecsForegroundAudioSession.h, SpecsForegroundAudioSessionCoordinator.hspecs_foreground_audio-lspecs_foreground_audio
SpecsCameraManager.h, SpecsCameraStructures.h, SpecsCameraDefinitions.hspecs_camera-lspecs_camera
SpecsLocationProvider.h, SpecsLocationDefinitions.hspecs_location-lspecs_location
SpecsLog.hspecs_log-lspecs_log
SpecsFs.hNone: header-only on the deviceNone

Example CMakeLists.txt:

cmake_minimum_required(VERSION 3.15)
project(MyNativeLens C CXX)

add_library(mynativelens SHARED
src/binding.cpp
src/player.cpp
src/audio.cpp
)
target_compile_features(mynativelens PRIVATE cxx_std_20)

# Link only what you use
target_link_libraries(mynativelens PRIVATE
specs_player
specs_audio_playback
)

All SPECS libraries are versioned shared objects (libspecs_*.so.<major>.<minor>.<patch>, SONAME libspecs_*.so.<major>: libspecs_camera.so.2 for SpecsCamera, libspecs_*.so.1 for the others) located in sysroots/armv8a-snap-linux/usr/lib/. The CMake sysroot setting ensures they are found automatically.

Use pkg-config with the SPECS NDK

The toolchain pre-configures PKG_CONFIG_LIBDIR and PKG_CONFIG_SYSROOT_DIR to point at the target sysroot. You can use CMake's PkgConfig module directly:

find_package(PkgConfig REQUIRED)
pkg_check_modules(CURL REQUIRED libcurl)
pkg_check_modules(OPENSSL REQUIRED openssl)

target_include_directories(myapp PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(myapp PRIVATE ${CURL_LIBRARIES})

pkg-config .pc files are in sysroots/armv8a-snap-linux/usr/lib/pkgconfig/ and sysroots/armv8a-snap-linux/usr/share/pkgconfig/.