0

In my CMAKE project I use currently the source code to compile a library and finaly use it to link with an JNI Library. I want to remove now the build step for my library FoxSDKCore and just to build the JNI library and link it with the prebuild FoxSDKCore.

My script looks currently like:

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

set(PATH_TO_FOXSDK "~/Downloads/fosdkcore")
message(${PATH_TO_FOXSDK})

add_definitions(-DLINUX)
add_definitions(-D_FILE_OFFSET_BITS=64)
set( CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++" )
set(CMAKE_BUILD_TYPE Debug)

include_directories(${PATH_TO_FOXSDK}/Include)
include_directories(${PATH_TO_FOXSDK}/Development/winhdrs)
include_directories(${PATH_TO_FOXSDK}/Development/SDK)
find_package(JNI)

if (JNI_FOUND)
    message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
    message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
endif()

include_directories(${JNI_INCLUDE_DIRS})

set(fox_files
        ${PATH_TO_FOXSDK}/Development/SDK/CallBacks.h
       ...
        )


add_library(FoxSDKCore
        SHARED
        ${fox_files})

add_library( # Sets the name of the library.
        JNIViie
        # Sets the library as a shared library.
        SHARED
        # Provides a relative path to your source file(s).
        JNIViie.cpp
        )

target_link_libraries(FoxSDKCore
        ${CMAKE_THREAD_LIBS_INIT}
        )

target_link_libraries( # Specifies the target library.
        JNIViie
        FoxSDKCore)

As far as I understand I have to set the IMPORTED flag, so I use



add_library(FoxSDKCore
        SHARED
        IMPORTED)

add_library( # Sets the name of the library.
        JNIViie
        # Sets the library as a shared library.
        SHARED
        # Provides a relative path to your source file(s).
        JNIViie.cpp
        )

target_link_libraries( # Specifies the target library.
        JNIViie
        FoxSDKCore)

But this will fail. Any hint how to link the existing library?

ingo
  • 776
  • 1
  • 10
  • 25
  • `link it with the prebuild FoxSDKCore` So where is the already build library? – KamilCuk Aug 18 '20 at 14:25
  • Does this answer your question? [CMake link to external library](https://stackoverflow.com/questions/8774593/cmake-link-to-external-library) You appear to create an `IMPORTED` target, but you don't tell CMake **where** it exists. See the duplicate question and the most up-voted response for the missing CMake command you need. – Kevin Aug 18 '20 at 14:31
  • The library is located in the working directory where CMake will generate the files to and also put compiled libs to. I thought this I do not need to tell CMake – ingo Aug 18 '20 at 15:01
  • You almost **always** need to specify the location of external pre-built libraries, unless they have been installed in the default standard *system* library paths. – Kevin Aug 18 '20 at 15:40

0 Answers0