kubernetes-client / c

Official C client library for Kubernetes
Apache License 2.0
141 stars 45 forks source link

can not compile for centos 7 #175

Closed olegzhr closed 1 year ago

olegzhr commented 1 year ago

Can not compile sources for Centos 7 according to installation instructions (for ubuntu it work) I got next error message:

/home/alertflex/c/kubernetes/src/list.c: In function ‘list_getElementAt’: /home/alertflex/c/kubernetes/src/list.c:155:9: error: ‘for’ loop initial declarations are only allowed in C99 mode for(int i = 0; i < indexOfElement; i++) { ^ /home/alertflex/c/kubernetes/src/list.c:155:9: note: use option -std=c99 or -std=gnu99 to compile your code /home/alertflex/c/kubernetes/src/list.c:163:9: error: ‘for’ loop initial declarations are only allowed in C99 mode for(int i = 1; i < (list->count - indexOfElement); i++) { ^ make[2]: [CMakeFiles/kubernetes.dir/src/list.c.o] Error 1 make[1]: [CMakeFiles/kubernetes.dir/all] Error 2

brendandburns commented 1 year ago

This library is currently only tested on Debian based distributions, but that said, it looks like you should be able to add the arguments (-std=c99 or -std=gnu99) and make it work.

If you figure it out, we'd take a PR with the fix.

ityuhui commented 1 year ago

I searched from the web and found this answer: https://stackoverflow.com/questions/24840030/forcing-c99-in-cmake-to-use-for-loop-initial-declaration

Adding the following line to CMakeLists.txt might be a quick fix.

set(CMAKE_C_STANDARD 99)
olegzhr commented 1 year ago

Thank you, this string solves problem - set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")

also there is problem exist with Libcurl from Centos 7 distr that is incompatible (old version) with kubernetes client I solve it by install libcurl from github:

git clone https://github.com/curl/curl.git cd curl ./buildconf ./configure --with-openssl make sudo make install sudo bash -c "echo '/usr/local/lib' >> /etc/ld.so.conf"