I am very new to C++ and all the associated terms and toolchains. I am trying to build a static library that customers can use in their own projects. Ideally, I would like to send them nothing but an .a and a .lib file, plus an .h file.
Right now, my CMake file looks like this:
project(ava-engine-client)
cmake_minimum_required(VERSION 3.9.6)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a )
add_compile_options(-std=c++11)
# GRPC and Protocol Buffers libraries location
list(APPEND CMAKE_PREFIX_PATH "/opt/grpc" "/opt/protobuf")
# CMake find modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
# Recurse and find all the generated Protobuf .cc files
file(GLOB_RECURSE PROTO_GEN_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/ava_engine/ava/*.cc)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
# Building the library
add_library(ava_engine_client STATIC src/AvaEngineClient.cc src/AvaEngineClient.h ${PROTO_GEN_SRCS})
target_link_libraries(ava_engine_client ${PROTOBUF_LIBRARIES} ${GRPC_LIBRARY})
## Building Playground
add_executable(playground src/Playground.cc)
target_link_libraries(playground ava_engine_client)
Now this fails at the linking stage, because I don't link the playground target, with the dependencies inside the ava_engine_client library:
Undefined symbols for architecture x86_64:
"grpc::ClientContext::ClientContext()", referenced from:
...
"grpc::ClientContext::~ClientContext()", referenced from:
...
"grpc::CreateChannel(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<grpc::ChannelCredentials> const&)", referenced from:
...
"grpc::g_core_codegen_interface", referenced from:
...
This isn't what I want, because it would require the customer to link with dependencies in my library (which doesn't' seem right to me).
Now, I have read a few Stack Overflow posts like this one: (CMake: include library dependencies in a static library) that suggest using CMAKE_CXX_ARCHIVE_CREATE to create an archive file. Is this the approach I should take? Is what I want even possible?