Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Fatal Error: linux/compiler_types.h: No such file or directory #393

Closed
mj1595 opened this issue May 20, 2020 · 5 comments
Closed

Fatal Error: linux/compiler_types.h: No such file or directory #393

mj1595 opened this issue May 20, 2020 · 5 comments

Comments

@mj1595
Copy link

mj1595 commented May 20, 2020

I am trying to add mptcp linux kernel header files path into my code but I am getting the error given below. I had a look into the issues that were mentioned here already. I did use gcc -I /usr/src/linux-headers-4.19.55.mptcp/include/uapi. Kindly let me know what to be done?

mj@mj-HP-EliteBook-840-G2:~/ver11_marie/rude$ make all
make[1]: Entering directory '/home/bosch/ver11_marie/rude/rude'
gcc -O2 -Wall -I /usr/src/linux-headers-4.19.55.mptcp/include/uapi -I../include -DHAVE_CONFIG_H -c -o flow_cntl.o flow_cntl.c
In file included from /usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/byteorder/little_endian.h:12:0,
                 from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
                 from /usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/tcp.h:25,
                 from ../include/rude.h:26,
                 from flow_cntl.c:25:
/usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/types.h:10:2: warning: #warning "Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders" [-Wcpp]
 #warning "Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders"
  ^~~~~~~
In file included from /usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/posix_types.h:5:0,
                 from /usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/types.h:14,
                 from /usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/byteorder/little_endian.h:12,
                 from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
                 from /usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/tcp.h:25,
                 from ../include/rude.h:26,
                 from flow_cntl.c:25:
/usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/stddef.h:2:10: fatal error: linux/compiler_types.h: No such file or directory
 #include <linux/compiler_types.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:38: recipe for target 'flow_cntl.o' failed
make[1]: *** [flow_cntl.o] Error 1
make[1]: Leaving directory '/home/bosch/ver11_marie/rude/rude'
make[1]: Entering directory '/home/bosch/ver11_marie/rude/crude'
gcc -O2 -Wall -I /usr/src/linux-headers-4.19.55.mptcp/include/uapi -I../include -DHAVE_CONFIG_H -c -o main.o main.c
In file included from /usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/byteorder/little_endian.h:12:0,
                 from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
                 from /usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/tcp.h:25,
                 from ../include/rude.h:26,
                 from main.c:25:
/usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/types.h:10:2: warning: #warning "Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders" [-Wcpp]
 #warning "Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders"
  ^~~~~~~
In file included from /usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/posix_types.h:5:0,
                 from /usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/types.h:14,
                 from /usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/byteorder/little_endian.h:12,
                 from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
                 from /usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/tcp.h:25,
                 from ../include/rude.h:26,
                 from main.c:25:
/usr/src/linux-headers-4.19.55.mptcp/include/uapi/linux/stddef.h:2:10: fatal error: linux/compiler_types.h: No such file or directory
 #include <linux/compiler_types.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:38: recipe for target 'main.o' failed
make[1]: *** [main.o] Error 1
make[1]: Leaving directory '/home/bosch/ver11_marie/rude/crude'
Makefile:18: recipe for target 'all' failed
make: *** [all] Error 2
@matttbe
Copy link
Member

matttbe commented May 20, 2020

Hello,

I think that as a workaround, you can include these three folders in this order:

  • -I/usr/src/linux-headers-4.19.55.mptcp/include/generated/uapi
  • -I/usr/src/linux-headers-4.19.55.mptcp/include/uapi
  • -I/usr/src/linux-headers-4.19.55.mptcp/include

But that's a workaround and apparently not recommended. I would suggest you to follow instructions from https://kernelnewbies.org/KernelHeaders#User_space_programs

The correct way to package the header files for a distribution is to run 'make headers_install' from the kernel source directory to install the headers into /usr/include and then rebuild the C library package, with a dependency on the specific version of the just installed kernel headers.

If you are distributing a user space program that depends on a specific version of some kernel headers, e.g. because your program runs only on patched or very recent kernels, you cannot rely on the headers in /usr/include. You also cannot use the header files from /usr/src/linux/include or /lib/modules/*/build/include/ because they have not been prepared for inclusion in user space. The kernel should warn you about this if you try it and point you to this Wiki page. The correct way to address this problem is to isolate the specific interfaces that you need, e.g. a single header file that is patched in a new kernel providing the ioctl numbers for a character device used by your program. In your own program, add a copy of that source file, with a notice that it should be kept in sync with new kernel versions. If your program is not licensed under GPLv2, make sure you have permission from the author of that file to distribute it under the license of your own program. Since your program now depends on kernel interfaces that may not be present in a regular kernel, it's a good idea to add run-time checks that make sure the kernel understands the interface and give a helpful error message if there is no fallback to an older interface.

Please re-open this issue if it doesn't help.

@cxht
Copy link

cxht commented Mar 2, 2021

Hello, I met the same problem that compiler_types.h:No such file or directory, and I have tried to include these three folders in this order,

  • -I/usr/src/linux-headers-4.19.55.mptcp/include/generated/uapi
  • -I/usr/src/linux-headers-4.19.55.mptcp/include/uapi
  • -I/usr/src/linux-headers-4.19.55.mptcp/include
    then a lot of redeclaration errors occur.
    How should I include to address this problem?

@matttbe
Copy link
Member

matttbe commented Mar 2, 2021

@cxht do you have other "include"? Which version of the MPTCP kernel are you using? What's the compiler command you used?

@cxht
Copy link

cxht commented Mar 8, 2021

@matttbe Thanks for your attention, I have addressed this problem after checking include headers, but another problem appears. When I call getsockopt() function, it always return -1. Is the location of getsockopt wrong or other?

My entire code is here:

#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <linux/tcp.h>
#include <stdio.h>
#define MPTCP_INFO_FLAG_SAVE_MASTER 0x01
    
int main()
{
    struct mptcp_info minfo;
    struct mptcp_meta_info meta_info;
    struct tcp_info initial;
    struct tcp_info others[3];
    struct mptcp_sub_info others_info[3];
    int val = MPTCP_INFO_FLAG_SAVE_MASTER;
    minfo.tcp_info_len = sizeof(struct tcp_info);
    minfo.sub_len = sizeof(others);
    minfo.meta_len = sizeof(struct mptcp_meta_info);
    minfo.meta_info = &meta_info;
    minfo.initial = &initial;
    minfo.subflows = &others;
    minfo.sub_info_len = sizeof(struct mptcp_sub_info);
    minfo.total_sub_info_len = sizeof(others_info);
    minfo.subflow_info = &others_info;    
    int sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if(sockfd == -1)
        printf("\nsocket error");
    struct sockaddr_in serv_addr;
    memset(&serv_addr, 0, sizeof(serv_addr)); 
    serv_addr.sin_family = AF_INET;            
    serv_addr.sin_addr.s_addr = inet_addr("10.2.0.1"); 
    serv_addr.sin_port = htons(8080);
    char pathmanager[] = "fullmesh";
    int a =setsockopt(sockfd, 6, MPTCP_PATH_MANAGER, pathmanager, sizeof(pathmanager));
    printf("\nfullmesh a=%d",a);
    char scheduler[] = "roundrobin";
    a = setsockopt(sockfd, 6, MPTCP_SCHEDULER, scheduler, sizeof(scheduler));
    printf("\nsch a=%d",a);
    connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
    a= setsockopt(sockfd, 6, MPTCP_INFO, &val, sizeof(val));
    printf("\n save master=%d",a);
    int m = getsockopt(sockfd, 6, MPTCP_INFO, &minfo, sizeof(minfo));
    if(m==-1)
    {
        printf("\ncannot getsockopt(MPTCP_INFO)");
        //printf("\nerrno = %s\n",strerror(errno));
    }
    printf("bytes:%d\nuna:%d\nrtt:%d\n",minfo.initial->tcpi_bytes_sent,minfo.initial->tcpi_unacked,minfo.initial->tcpi_rtt);
    char sendbuf[1024];
    char recvbuf[1024];
    FILE *f ;
    f=fopen("random","r");
    while(fgets(sendbuf, sizeof(sendbuf), f) > 0)
    {
        send(sockfd, sendbuf, strlen(sendbuf),0); 
        if(strcmp(sendbuf,"exit\n")==0)
            break;
        recv(sockfd, recvbuf, sizeof(recvbuf),0); 
        //fputs(recvbuf, stdout);
        memset(sendbuf, 0, sizeof(sendbuf));
        memset(recvbuf, 0, sizeof(recvbuf));
    }
    close(sockfd);
    close(f);
    return 0;
}

@matttbe
Copy link
Member

matttbe commented Mar 8, 2021

Thanks for your attention, I have addressed this problem after checking include headers

Good! We can keep this ticket closed.

but another problem appears. When I call getsockopt() function, it always return -1. Is the location of getsockopt wrong or other?

The issue seems different, may you create a new ticket with an answer for all these questions:

  • What's the errno value? (number + message)
  • Which kernel are you using?
  • How did you install it?
  • Which command are you using to compile this code?
  • All the previous setsockopt here were OK?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants