2

I am just starting to grasp NDK with Android.

I am trying to include library header files and therefore compile a third party library as a dependency with my project.

However I am not able to include the library, and I feel that I am doing this wrong.

My project structure

jni
--mylib.cpp
--CMakeLists.txt
----libs
------firpm_d
--------CMakeLists.txt
--------src
--------include
----------firpm
------------pm.h

My CMakeLists.txt looks as follows

# Cmake Minimum Version
cmake_minimum_required(VERSION 3.4.1)
project(MyLib)

# Add libraries

FOREACH(subdir ${SUBDIRS})
  ADD_SUBDIRECTORY(${subdir})
ENDFOREACH()

add_library(mylib SHARED
            mylib.cpp)

# Link
target_link_libraries(
            mylib
            android
            log)

And in my mylib.cpp file I am including the third party lib as follows

#include "lib/firpm_d/include/firpm/pm.h"

But when I try to compile it gives me an error

Error:(25) undefined reference to 'firpm(unsigned int, std::vector<double, std::allocator<double> > const&, std::vector<double, std::allocator<double> > const&, std::vector<double, std::allocator<double> > const&, double, int)'

Maybe I need to set LOCAL_C_INCLUDES, but I haven't found any information how to do this with new build tools and CMake

And by the way Android Studio doesn't highlight any line as problematic.

I would be grateful for any help or advice.

  • `undefined reference` has nothing common with missed include files. As opposite, `undefined reference` means that include file, **declaring** given symbol, has been found. But there is no file which **defines** given symbol. It should be either source file or library, with which you should link ([target_link_libraries](https://cmake.org/cmake/help/v3.9/command/target_link_libraries.html)). – Tsyvarev Nov 18 '17 at 22:32
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Tsyvarev Nov 18 '17 at 22:32
  • @Tsyvarev, could you please provide an example of how to include source files into my build ? –  Nov 19 '17 at 05:44
  • In your case it, probably, should be a **library**, created in `jni/libs/firpm_d/CMakeLists.txt`. You need to link main library `mylib` with given one, using `target_link_libraries`. – Tsyvarev Nov 19 '17 at 16:14

0 Answers0