C++ undefined reference to some of defined functions in linked library of CMake project

Ted James
2 min readMay 6, 2024

I’m trying to use the kubernetes c client api libraryrel=”nofollow noreferrer”>[https://github.com/kubernetes-client/c/].
I just created a CMake C++ project. The project contain only CMakeLists.txt and main.cpp files. I have followed the instructions to install the client library and libkubernetes.so is found on /usr/local/lib
Following is my code.

CMakeLists.txt

cmake_minimum_required(VERSION 3.25)
project(k8s)

set(CMAKE_CXX_STANDARD 17)

add_executable(k8s main.cpp)

target_link_libraries(k8s PRIVATE /usr/local/lib/libkubernetes.so)

main.cpp

#include <iostream>

#include <kubernetes/include/apiClient.h>
#include <kubernetes/config/kube_config.h>
#include <kubernetes/api/CoreV1API.h>

int main() {
char *basePath = NULL;
sslConfig_t *sslConfig = NULL;
list_t *apiKeys = NULL;
int rc = load_kube_config(&basePath, &sslConfig, &apiKeys, NULL);/* NULL means loading configuration from $HOME/.kube/config */
if (rc != 0) {
printf("Cannot load kubernetes configuration.\n");
return -1;
}

// commented below for [check 1]
apiClient_t *apiClient = apiClient_create_with_base_path(basePath, sslConfig, apiKeys);
if (!apiClient) {
printf("Cannot create a kubernetes client.\n");
return -1;
}

v1_pod_list_t *pod_list = NULL;
pod_list =

--

--

Ted James

The world is my office, and every destination is my inspiration