kubernetes-client / c

Official C client library for Kubernetes
Apache License 2.0
148 stars 49 forks source link

How to compile as static .a file? #220

Closed Jeansen closed 4 months ago

Jeansen commented 9 months ago

I am not too deep into C, but I would like to consume this API and integrate it as a static library (.a) instead of a shared object (.so). How to achieve this?

ityuhui commented 9 months ago

Patch the following code to "kubernetes/CMakeLists.txt"

diff --git a/kubernetes/CMakeLists.txt b/kubernetes/CMakeLists.txt
index 592c445..9f65ff8 100644
--- a/kubernetes/CMakeLists.txt
+++ b/kubernetes/CMakeLists.txt
@@ -1302,7 +1302,7 @@ include(PreTarget.cmake OPTIONAL)
 set(PROJECT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")

 # Add library with project file with project name as library name
-add_library(${pkgName} ${SRCS} ${HDRS})
+add_library(${pkgName} STATIC ${SRCS} ${HDRS})
 # Link dependent libraries
 if(NOT CMAKE_VERSION VERSION_LESS 3.4)
     target_link_libraries(${pkgName} PRIVATE OpenSSL::SSL OpenSSL::Crypto)
Jeansen commented 9 months ago

OK, that worked, I got a libkubernetes.a file now. Unfortunately, when I try to include it in a binary and build that one, I get:

/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64encode: error: undefined reference to 'BIO_f_base64'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64encode: error: undefined reference to 'BIO_new'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64encode: error: undefined reference to 'BIO_s_mem'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64encode: error: undefined reference to 'BIO_new'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64encode: error: undefined reference to 'BIO_push'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64encode: error: undefined reference to 'BIO_set_flags'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64encode: error: undefined reference to 'BIO_write'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64encode: error: undefined reference to 'BIO_ctrl'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64encode: error: undefined reference to 'BIO_ctrl'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64encode: error: undefined reference to 'BIO_ctrl'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64encode: error: undefined reference to 'BIO_free_all'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64encode: error: undefined reference to 'BUF_MEM_grow'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64decode: error: undefined reference to 'BIO_f_base64'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64decode: error: undefined reference to 'BIO_new'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64decode: error: undefined reference to 'BIO_s_mem'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64decode: error: undefined reference to 'BIO_new'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64decode: error: undefined reference to 'BIO_write'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64decode: error: undefined reference to 'BIO_push'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64decode: error: undefined reference to 'BIO_set_flags'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64decode: error: undefined reference to 'BIO_read'
/tmp/included5619073151443731897/libkubernetes.a(binary.c.o):binary.c:function base64decode: error: undefined reference to 'BIO_free_all'

I know, this is some special case because I try to include it in a Kotlin Native build. So far the native build works fine wit the shared object files, but I'd like to not rely on them because they are manually compiled.

So, maybe I am just missing something. If this is something where you could point me to the right directions, I'd appreciate it.

ityuhui commented 9 months ago

The error message shows that libkubernetes.a cannot obtain the dependency of libssl. Try including the OpenSSL library (e.g. libssl.a) in your binary.

k8s-triage-robot commented 6 months ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot commented 5 months ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot commented 4 months ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-ci-robot commented 4 months ago

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to [this](https://github.com/kubernetes-client/c/issues/220#issuecomment-2236000131): >The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. > >This bot triages issues according to the following rules: >- After 90d of inactivity, `lifecycle/stale` is applied >- After 30d of inactivity since `lifecycle/stale` was applied, `lifecycle/rotten` is applied >- After 30d of inactivity since `lifecycle/rotten` was applied, the issue is closed > >You can: >- Reopen this issue with `/reopen` >- Mark this issue as fresh with `/remove-lifecycle rotten` >- Offer to help out with [Issue Triage][1] > >Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community). > >/close not-planned > >[1]: https://www.kubernetes.dev/docs/guide/issue-triage/ Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.