string.h: No such file or directory upon trying to build using kbuild Makefile
I’m trying to send a string to the kernel module from the user space and the kernel returns back the string reversed. I followed a simple example code and added strrev() function in the kernel code which is defined in the string.h header. But that gives me an error «fatal error: string.h: No such file or directory» and no other error. The user code is same as the sample code from the link. Can anybody explain why this is happening ?
User Code
#include #include #include #include #include #include #define NETLINK_USER 31 #define MAX_PAYLOAD 1024 /* maximum payload size*/ struct sockaddr_nl src_addr, dest_addr; struct nlmsghdr *nlh = NULL; struct iovec iov; int sock_fd; struct msghdr msg; int main() < char str[20]; sock_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_USER); if (sock_fd < 0) return -1; memset(&src_addr, 0, sizeof(src_addr)); src_addr.nl_family = AF_NETLINK; src_addr.nl_pid = getpid(); /* self pid */ bind(sock_fd, (struct sockaddr *)&src_addr, sizeof(src_addr)); memset(&dest_addr, 0, sizeof(dest_addr)); dest_addr.nl_family = AF_NETLINK; dest_addr.nl_pid = 0; /* For Linux Kernel */ dest_addr.nl_groups = 0; /* unicast */ nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(MAX_PAYLOAD)); memset(nlh, 0, NLMSG_SPACE(MAX_PAYLOAD)); nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD); nlh->nlmsg_pid = getpid(); nlh->nlmsg_flags = 0; printf("Enter a string for reversal:- "); scanf("%s",str); strcpy(NLMSG_DATA(nlh),str); iov.iov_base = (void *)nlh; iov.iov_len = nlh->nlmsg_len; msg.msg_name = (void *)&dest_addr; msg.msg_namelen = sizeof(dest_addr); msg.msg_iov = &iov; msg.msg_iovlen = 1; printf("\nSending message to kernel\n"); sendmsg(sock_fd, &msg, 0); printf("Waiting for message from kernel\n"); /* Read message from kernel */ recvmsg(sock_fd, &msg, 0); printf("Received message payload: %s\n", NLMSG_DATA(nlh)); close(sock_fd); return 0; >
Kernel Code
#include #include #include #include #include #define NETLINK_USER 31 struct sock *nl_sk = NULL; static void hello_nl_recv_msg(struct sk_buff *skb) < struct nlmsghdr *nlh; int pid; struct sk_buff *skb_out; int msg_size; char msg[20]; int res; printk(KERN_INFO "Entering: %s\n", __FUNCTION__); nlh = (struct nlmsghdr *)skb->data; printk(KERN_INFO "Netlink received msg payload:%s\n", (char *)nlmsg_data(nlh)); pid = nlh->nlmsg_pid; /*pid of sending process */ strcpy(msg,strrev((char *)nlmsg_data(nlh))); msg_size = strlen(msg); skb_out = nlmsg_new(msg_size, 0); if (!skb_out) < printk(KERN_ERR "Failed to allocate new skb\n"); return; >nlh = nlmsg_put(skb_out, 0, 0, NLMSG_DONE, msg_size, 0); NETLINK_CB(skb_out).dst_group = 0; /* not in mcast group */ strncpy(nlmsg_data(nlh), msg, msg_size); res = nlmsg_unicast(nl_sk, skb_out, pid); if (res < 0) printk(KERN_INFO "Error while sending bak to user\n"); >static int __init hello_init(void) < printk("Entering: %s\n", __FUNCTION__); //nl_sk = netlink_kernel_create(&init_net, NETLINK_USER, 0, hello_nl_recv_msg, NULL, THIS_MODULE); struct netlink_kernel_cfg cfg = < .input = hello_nl_recv_msg, >; nl_sk = netlink_kernel_create(&init_net, NETLINK_USER, &cfg); if (!nl_sk) < printk(KERN_ALERT "Error creating socket.\n"); return -10; >return 0; > static void __exit hello_exit(void) < printk(KERN_INFO "exiting hello module\n"); netlink_kernel_release(nl_sk); >module_init(hello_init); module_exit(hello_exit); MODULE_LICENSE("GPL");
Terminal window
make -C /lib/modules/4.15.0-1096-oem/build/ M=/home/Username/Documents/Task_KtoUcom modules make[1]: Entering directory '/usr/src/linux-headers-4.15.0-1096-oem' CC [M] /home/Username/Documents/Task_KtoUcom/kernl.o /home/Username/Documents/Task_KtoUcom/kernl.c:5:9: fatal error: string.h: No such file or directory #include ^~~~~~~~~~ compilation terminated. scripts/Makefile.build:337: recipe for target '/home/Username/Documents/Task_KtoUcom/kernl.o' failed make[2]: *** [/home/Username/Documents/Task_KtoUcom/kernl.o] Error 1 Makefile:1585: recipe for target '_module_/home/Username/Documents/Task_KtoUcom' failed make[1]: *** [_module_/home/Username/Documents/Task_KtoUcom] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-1096-oem' Makefile:4: recipe for target 'all' failed make: *** [all] Error 2
Подключение string.h
Здравствуйте. Недавно пересел на Debian 6.0 и g++. попробовал компилировать приложение из нескольких файлов — возникла проблема — перестал видеть string. ругаеться вот так:
g++ main.cpp complex.cpp -o prog
In file included from main.cpp:2:
complex.h:19: error: ‘string’ does not name a type
In file included from complex.cpp:2:
complex.h:19: error: ‘string’ does not name a type
прога из 3х простых файлов: main.cpp complex.h complex.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#ifndef COMPLEX_H_ #define COMPLEX_H_ #include #include class Complex { public: Complex(){}; Complex(int TheReal, int TheImage); ~Complex(){}; int real; int image; string q; void print(); }; #endif /*COMPLEX_H_*/
переменная string q используется только в этом файле(complex.h).
Причем что интересно — при скидывании всего кода в одну кучу (в main.cpp) все работает как часы..
В чем может быть проблема? помогите плиииз.
Перевод слова их переменной string в другую переменную string для вывода ее отдельно от всей строки
У меня есть код, я выполняю задание учителя. В этом задании мне надо ввести кол слов, а также.
Нельзя преобразовать тип Tuple к string
Здравствуйте, у меня возникла проблема. При запуске кода, вылезает ошибка "Нельзя преобразовать тип.
Повторное подключение к БД (connection string)
Подскажите плиз, как сделать, чтобы при неоткрывшемся соединении (connection not opened) программа.
Подключение библиотеки string.h для объединения строк
Здравствуйте! Подскажите как правильно подключить string.h, пробывал вот так: #include.
How to inline string.h function on linux?
I want to optimize some code such that all the functions in string.h will be inlined. I’m on x86_64. I’ve tried -O3, -minline-all-stringops and when I do «nm a.out» it shows it is calling the glibc version. Checking with gcc -S, I see the calls. What am I missing? There are dozens of #ifdef _SOME_SETTING_ in string.h, and bits/string3.h shows the inline version, but I don’t know how to get there. for example:
$ cat test.c #include main() < char *a, *b; strcpy(b,a); >/* When compiled with: gcc -minline-all-stringops -O6 -I. -S -o test.S test.c Produces: .file "test.c" .text .p2align 4,,15 .globl main .type main, @function main: .LFB12: .cfi_startproc subq $8, %rsp .cfi_def_cfa_offset 16 xorl %esi, %esi xorl %edi, %edi call strcpy addq $8, %rsp .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE12: .size main, .-main .ident "GCC: (GNU) 4.5.1 20100924 (Red Hat 4.5.1-4)" .section .note.GNU-stack,"",@progbits */
1 Answer 1
If a function implementation is not in the header file and in a separate compilation unit, it cannot be inlined unless you have a compiler that can do LTCG.
Sounds like you’ll need to write the implementation yourself.
I can but don’t want to and there are inline versions including the implementatino in the header which I thought I indicated (in bits/string3.h included some unknown way in string.h). I need the magic incantation to make string.h use the inlines.
I don’t see anything in your code that includes the inlined version. Unless your compilation unit contains the inlined version (usually by including the relevant header file), the compiler can’t inline. That’s all.
The inlines are in bits/string3.h, but it says I should NOT include it directly. Gcc will define or set things to pick the inlining.
No such file or directory #include [closed]
This question was closed because it is not about an official Ubuntu flavor. It is not currently accepting answers.
This is not about an official Ubuntu flavor. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow.
kai.c:5:18: fatal error: string: No such file or directory #include ^ compilation terminated.
gcc version is: (Ubuntu 4.8.2-19ubuntu1) 4.8.2
2 Answers 2
Rename your file to kai.cpp
And compile it with g++ kai.cpp -o kai
@qwerty Everything from C is available in C++ (I think). If you want to use C++, use the g++ command instead of gcc to compile the code. g++ is the GNU C++ compiler, while gcc is the C compiler. On C,
The string library is the file string.h , so:
#include "string.h" #include "stdio.h" void main() < char src[2] = "Hi"; char dest[2]; strcpy(dest, src); printf("%s\n", dest); // Will print Hi >
Related
Hot Network Questions
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.12.43529
Ubuntu and the circle of friends logo are trade marks of Canonical Limited and are used under licence.
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.