3
votes

I modified some files in the Linux kernel

include/linux/tcp.h
include/net/tcp.h 
net/ipv4/sysctl_net_ipv4.c
net/ipv4/tcp_output.c

Following this i compiled the modified Linux kernel

$ make modules_install  
$ make headers_install INSTALL_HDR_PATH=/usr/include  
$ make install  

The new kernel can start, everything seems normal. But when i tried to include the modified kernel header in my app, the compiler complains that the header does NOT define the types which i have just added. Upon checking /usr/include/netinet/tcp.h, i find that it is NOT the file i modified.

Q. How can i properly export modified Linux kernel headers to include in a C program ?

3
in my app, i use this: #include <netinet/tcp.h>, but the tcp.h is not my modification file - xiao su
/usr/include/linux/tcp.h and /usr/include/netinet/tcp.h are both separate files. Can you try using #include <linux/tcp.h> in your C program and see if it works properly?... - TheCodeArtist
I need to get clarify have u ran a command make before make modules_install - vinay hunachyal
yes, i make -j5, make moudles_install, make headers_install, and make install. i don't know how to update the system's header file to my modification file. but i found another way to compile my c app, i added TCP_CWND type in <netinet/tcp.h>, i stil include the old version header of <netinet/tcp.h>, but i added "#define TCP_CWND 19" - xiao su
to my c app, it can work, i still don't know how to update the header file, but this way can compile my c app, and the C app run properly. - xiao su

3 Answers

1
votes

A. Copy them to somewhere the code expects to find them, such as a directory you then pass to the compiler via -I, and then make sure that the code actually includes them.

1
votes

As you are changing some linux header, do a make first to see whether there are any side effects. The kernel might not compile. This is absolutely necessary.

I think make is also necessary for the changes to take effect for the kernel headers so that they can be exported to user space.

Just doing make modules_install will install already built modules, the modules won't be recompiled against the changed headers. Similarly for other install commands.

0
votes

The right location of INSTALL_HDR_PATH should be /usr instead:

$ make headers_install INSTALL_HDR_PATH=/usr