Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Cmake cannot determine linker language for target

I tried linking my root app/ file to a C++ project, but keep getting this error.

CMake Error at CMakeLists.txt:15 (add_library):


    src/main/cpp/iob.c


  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp


  .hxx .in .txx


CMake Error: CMake can not determine linker language for target: iob

I have my CMakeLists.txt file inside of src/min/cpp along with the iob.c file it says it can't find. What am I doing wrong?

This is my CMakeLists.txt

# Sets the minimum version of CMake required to build your native library.
# This ensures that a certain set of CMake features is available to
# your build.

cmake_minimum_required(VERSION 3.4.1)

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

# Specifies a library name, specifies whether the library is STATIC or
# SHARED, and provides relative paths to the source code. You can
# define multiple libraries by adding multiple add.library() commands,
# and CMake builds them for you. When you build your app, Gradle
# automatically packages shared libraries with your APK.

add_library( # Specifies the name of the library.
         iob

         # Sets the library as a shared library.
         SHARED

         # Provides a relative path to your source file(s).
         src/main/cpp/iob.c )
like image 628
Rafa Avatar asked Oct 22 '18 04:10

Rafa


1 Answers

If CMakeLists.txt is in src/main/cpp directory (this is how the AS wizard generates a C++ project), then you should say

add_library( # Specifies the name of the library.
     iob

     # Sets the library as a shared library.
     SHARED

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

Relative paths to source files are calculated relative to the CMakeLists.txt.

like image 93
Alex Cohn Avatar answered Oct 15 '22 02:10

Alex Cohn