error: asm/socket.h: No such file or directory and solution

Someday i want to compile this very simple socket program on RHEL5 Linux when get error like that.

#include <sys/types.h>
#include <sys/socket.h>main() {
  int svr_sd = socket(AF_INET, SOCK_STREAM, 0 );
  return 0;
}:

Diagnose:

#rpm -q kernel-headers
#rpm -V kernel-headers // to verify that everytingk is OK, print nothing on OK, else here what will you get :

# rpm -V kernel-headers

missing     /usr/include/asm/socket.h

Solution :

#rpm -e –nodeps kernel-headers
#yum install kernel-headers

Note: on RHEL4 “kernel-headers” name is “glibc-kernheaders”

Moral of story:

Program error message already point to solution. Because we make an assumption that gcc/g++ can compile other program  we dont go to right direction. We ask , “how can possible asm/socket.h not found, i dont touch the system?”

Advertisements