0

I am trying to compile Bitcoin (Core) for Android using Android NDK in Android Studio, but I get a CMake Error: CMake can not determine linker language for target: bitcoin. I cloned the Bitcoin repository into app/src/main/cpp/bitcoin. My CMakeLists.txt (in app/src/main/cpp/CMakeLists.txt) is as follows:

cmake_minimum_required(VERSION 3.4.1)
project(bitcoin)
add_library(bitcoin SHARED bitcoin/src/)

I tried many solutions from this forum, including appending C CXX and CXX to the project name, adding an include_directories(bitcoin/src/), adding a set_target_properties(bitcoin PROPERTIES LINKER_LANGUAGE CXX), and various combinations of these, but the error persists. What am I doing wrong?

  • Just giving a `add_library` a source directory isn't going to work AFAIK. You're supposed to list every source file that should be built. [There are alternatives](https://stackoverflow.com/questions/1027247/is-it-better-to-specify-source-files-with-glob-or-each-file-individually-in-cmak), but I'm not sure whether they are considered good practice. – Michael Mar 10 '21 at 15:57
  • Strange that the [Android NDK documentation](https://developer.android.com/studio/projects/configure-cmake) doesn't mention that. I tried: `file(GLOB BITCOIN_FILES CONFIGURE_DEPENDS /bitcoin/src/.cpp /bitcoin/src/.h /bitcoin/src/*.hpp) add_library(bitcoin SHARED ${BITCOIN_FILES})` but this doesn't work. Should I call a separate `add_library(...)` for every `.cpp` file? –  Mar 10 '21 at 16:05
  • The globbing pattern `/bitcoin/src/*.cpp` means that files will be searched under **absolute path** `/bitcoin/src/`. For search files relative to the source directory, do not use forward slash: `bitcoin/src/*.cpp`. – Tsyvarev Mar 10 '21 at 16:08
  • _"the Android NDK documentation doesn't mention that"_ That page only has examples with a single source file. _"Should I call a separate add_library(...) for every .cpp file?"_ No. – Michael Mar 10 '21 at 16:11

0 Answers0