0

I have a c++ file and I want to link it my kotlin app but I dont want to link it .so file. I want to generat .a file and link it to my project. I want to add cpp files on my project because I have not static file. But android studio havenot generated static file. And I got an error. If I build libraries with SHARED parameter, everythings going well.

My CmakeLists file

cmake_minimum_required(VERSION 3.4.1)

add_library(
        delaunator-lib
        SHARED
        delaunator-lib.cpp)

add_library(
        delaunator-lib-static
        STATIC
        delaunator.h)

find_library(
        log-lib
        log)


target_link_libraries(
        delaunator-lib
        delaunator-lib-static
        ${log-lib})

I got a foloowing error while I was tring to build native part of code from gradle externalNativeBuildDebug. If I delete second add_library and add to delaunator.h file to first add library, everythings going well.

  CMake Error: CMake can not determine linker language for target: delaunator-lib-static
Yavuz
  • 13
  • 4
  • 1
    Your **static** library has **no source files** (`.h` is a *header* file), so there is nothing to compile and link about it. In your *shared* library you have `delaunator-lib.cpp` source file, why don't you use the same file for *static* library? Note, that the line `target_link_libraries(delaunator-lib delaunator-lib-static)` links your shared library with a static one. It doesn't link your app (and your code doesn't create any app). – Tsyvarev Jan 26 '20 at 12:09
  • Actually delaunator-lib.cpp is JNI file to communucate with c++ code(delaunator.h) so static and shared part is not same. I have no header file for delaunator class yet but is this situation couse an error? – Yavuz Jan 26 '20 at 12:22
  • I generate header file for delaunator class and added it to cmake shared field. My code build and running correctly but I have not found any .a file in my project sub directories. Is it normal? If it is normal, I can add my answer. – Yavuz Jan 26 '20 at 13:15
  • 1
    Once more: A *library* (whether shared or not) has **no sense** without **source** files. If you may omit linking with a library and this doesn't cause any "undefined reference" error, then the library is not needed at all. – Tsyvarev Jan 26 '20 at 16:46

0 Answers0