Based on tensorflow lite minimal example, I build a small application and want to share it as lib.
My CmakeList looks like that:
cmake_minimum_required(VERSION 3.16)
project(MY_LIB C CXX)
set(TENSORFLOW_SOURCE_DIR "" CACHE PATH
"Directory that contains the TensorFlow project"
)
if(NOT TENSORFLOW_SOURCE_DIR)
get_filename_component(TENSORFLOW_SOURCE_DIR
"~/tensorflow"
# "${CMAKE_CURRENT_LIST_DIR}/../../../../"
ABSOLUTE
)
endif()
add_subdirectory(
"${TENSORFLOW_SOURCE_DIR}/tensorflow/lite"
"${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite"
EXCLUDE_FROM_ALL
)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../results)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../results)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_library(MY_LIB SHARED
src/my_code.cpp
)
target_link_libraries(MY_LIB
tensorflow-lite
${CMAKE_DL_LIBS}
)
target_include_directories(MY_LIB PUBLIC
inc
)
When running build
, I get an .so file with ~ 5 MB, which works well even on machines without tensorflow (lite).
Then, I've replaced add_library(MY_LIB SHARED
by add_library(MY_LIB STATIC
and get the expected .a file. Surprisingly, this file has only 500 kB and lacks of symbols, when running it.
I assume that tensorflow content is part of shared lib, but referenced somehow externally in the static lib. What do I need to configure to get also the full code, without any external dependencies in the static lib?
I've read here that both kinds of lib contains the whole code.
Thanks.