Consider the following simple example below. Suppose I have library a
and library b
, where b
is linked to a
. I want to create a shared library b_merged
that contains all the compiled code necessary to use library b
. I want to be able to distribute this single shared library (b_merged
), which users can link to to use library b
. I don’t want to have to also distribute a
- I want it to be incorporated into b_merged
.
How should I make b_merged
? Below, I tried add_library(b_merged SHARED b)
, but then b_merged
does not end up containing func1
from library a
, so the build fails.
cmake_minimum_required(VERSION "3.14")
project(TEST LANGUAGES C)
add_library(a a.c)
add_library(b b.c)
target_link_libraries(b a)
add_library(b_merged SHARED b)
add_executable(test test.c)
target_link_libraries(test b_merged)
a.c
int func1(){return 0;}
b.c
int func2(){return 0;}
test.c
#include "stdio.h"
int func1();
int func2();
int main()
{
int a = func1();
int b = func2();
printf("Hello World\n");
return 0;
}