CMake Error at CMakeLists.txt (target_link_libraries) when adding logs

Viewed 1583

I have an ndk project with a CMakeLists.txt that looks like so

cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror")

add_library( # Specifies the name of the library.
        main

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        main.c)

target_link_libraries(
        android
        log
)

it follows the pattern laid out in all of the NDK example projects listed on the googlesamples github repo. I keep getting CMake Error at CMakeLists.txt (target_link_libraries), and it seems like most people are solving it with this line

add_library(debug <files Name>)

but no one is adding that for logging. What am I doing wrong?

2 Answers

add below to your CMakeLists.txt above the line of target_link_libraries.

find_library( # Sets the name of the path variable.
          log-lib

          # Specifies the name of the NDK library that
          # you want CMake to locate.
          log )

Then modify target_link_libraries as below for linking android log lib

target_link_libraries( # Specifies the target library.
                   main

                   # Links the target library to the log library
                   # included in the NDK.
                   ${log-lib} )

1) in your code source folder, look for something like "Android.mk" or "project.mk", then remember the path of it.

2) go to android studio and click File ==> link c++ project with gradle ==> choose build system ndk-build , then look for the .mk file you found first. click ok , and sync project.

Related