Ubuntu and libcap (features) undefined link

I am trying to compile the following minimal C code on ubuntu 10.10:

#include <sys/capability.h> void main(void) { cap_t cap; cap = cap_get_proc(); } 

with gcc -lcap test.c , which gives me the following error:

 /tmp/ccCQFyXS.o: In function `main': test.c:(.text+0x9): undefined reference to `cap_get_proc' collect2: ld a retourné 1 code d'état d'exécution 

I have libcap2-dev and libcap2-bin installed, version 2.21

 ls /lib/libcap.* /lib/libcap.a /lib/libcap.so /lib/libcap.so.2 /lib/libcap.so.2.21 

The same code with the same gcc command successfully linked to arch and gentoo

What should I do to create it on ubuntu?

+4
source share
3 answers

Try gcc -Wl,--no-as-needed -lcap test.c or gcc test.c -lcap .
Hope this helps!

+3
source

I am working on Ubuntu 10.04 and I had the same problem ( sys/capability.h not present on the file system ).

I solved this problem by installing the libcap-dev package (version 1: 2.17-2ubuntul) through Synaptic Package Manager, which populates the /usr/include/sys folder with the capability.h file.

+2
source

For RHEL:

 yum install libcap-devel gcc -lcap test.c 
0
source

Source: https://habr.com/ru/post/1384060/


All Articles