#include "linux/fanotify.h" // can work
#include "sys/fanotify.h" // error
The fanotify is a linux kernel.
When I want to init fanotify to watch a file:
use of undeclared identifier 'fanotify_init'
It's there a way to use the fanotify lib? What should I do in the CMakeLists.txt file?
Related
In my project I am using char driver to communicate between user space and kernel space. I use the function copy_to_user(void user *to, const void *from, unsigned long n) to copy data from kernel space to user space buffer. We can find this function under #include < asm/uaccess.h > header file.
I complied the project using Linux Kernel version 4.4.0-59-generic, Ubuntu OS version 16.04 LTS and its working fine without any error and warning. I get the desired output.
I compiled the same project using Linux kernel version 4.12.8, Ubuntu OS version 16.04.2 LTS and it throws me an warning during compile time WARNING: "copy_to_user" [/home/ldrv1/Desktop/Vijay/code/build/uts.ko] undefined!. When I do insmod of my module I get error as follows insmod: ERROR: could not insert module uts.ko: Unknown symbol in module. I think that #include <asm/uaccess.h> header file is still supported in 4.12.8 kernel version else I would have got fatal error: no such file or directory error while compiling. I tried updating the linux kernel headers using apt-get install linux-headers-$(uname -r) command and I got the following response:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-headers-4.12.8
E: Couldn't find any package by glob 'linux-headers-4.12.8'
E: Couldn't find any package by regex 'linux-headers-4.12.8'
This OS version 16.04.2 LTS has linux-headers-4.10.0-35.
How do I get rid of this warning? Suggestions and support appreciated. If more information is required please feel free to ask.
You should use #include <linux/uaccess.h> for 4.12.8.
Here is the definition.
In 4.4 some drivers use #include <asm/uaccess.h> whilst the others
use #include <linux/uaccess.h>.
#include <linux/uaccess.h> is preferable, I think.
You should do apt-get update and then apt-get install linux-headers-generic.
The function copy_to_user and copy_from_user defined in asm/uaccess.h . I think you have some issue when you define this function. I wrote the character device driver with some example about data transfer between Kernel space and User space. View my github: my code for reference. Please star if you feel it is helpful for you :). it has small bug in example 3. I am figuring them, but example 1 and example 2 work well
The answer given by Bronislav Elizaveti is correct. If instead of #include <asm/uaccess.h> we use #include <linux/uaccess.h>, then we won't get the warning.
If you still want to use only #include <asm/uaccess.h>, then you'll need to use _copy_to_user instead of copy_to_user (with the same arguments). A simple _ will do the job.
I am trying to auto-link following libraries. I've never used auto-linking feature and not sure how it works exactly. From my research this should work. When I include the dll to the project besides the SDL libraries I get following errors:
https://i.gyazo.com/e49a636ddad428fa48acdee78c930293.png
What are the steps to get Auto-linking working. Don't I need to specify some kind of path for this? Does it have to be in specific order?
This code is inside the DLL:
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
#include <SDL_ttf.h>
#pragma comment(lib, "SDL2.lib")
#pragma comment(lib, "SDL2main.lib")
#pragma comment(lib, "SDL2_image.lib")
#pragma comment(lib, "SDL2_mixer.lib")
#pragma comment(lib, "SDL2_ttf.lib")
Thank you for taking your time to answer.
You haven't explicitly specified what platform or development environment you're using, but it looks like you're using a recent version of Visual Studio. You need to configure the "VC++ Directories" settings in your project to include the paths for the lib files, under "Library Directories". These pragma directives will instruct the linker to search for the lib files in these directories.
The compiler complains that it can't find the header sdl.h, it hasn't gotten to the linking part (and I'm guessing it would have trouble there too).
To solve:
Add the path to the SDL headers here: project properties\ C/C++ \ General \Additional include directories
Add the path to your import libs here: project properties \ Linker \ General \ Additional Library directories.
Don't fiddle with 'VC++ directories' - as the name suggests, it is where the toolchain seeks various VC components (crt, mfc, open mp, windows sdk etc.). Messing this up could result in extremely hard to diagnose build failures.
I'm trying to use the create_proc_entry() function to create a directory under /proc. When I try to compile the code, I get the following error: implicit declaration of function 'create_proc_entry' .
These are the headers I have included in my .c file:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/string.h>
#include <linux/vmalloc.h>
#include <linux/uaccess.h>
The kernel version on the machine I'm trying to compile for is: 3.10.33-g7954807-dirty
Am i missing any headers necessary to call this method? Or is the method deprecated in my version of the kernel?
/proc filesystem has been refactored in 3.10, the function you are looking for has been removed, you should use the full featured proc_create function family. Note that the signatures are different.
3.10 version:
http://lxr.free-electrons.com/source/include/linux/proc_fs.h?v=3.10
3.9 version:
http://lxr.free-electrons.com/source/include/linux/proc_fs.h?v=3.9
You can find greater explanation of using full featured /proc functions in the book Linux Device Drivers 4, or, if you want shorter solution, check this link (https://github.com/jesstess/ldd4/blob/master/scull/main.c) where you can see how the struct file_operations has been used. You do not have to setup to all fields of the struct.
I am trying to compile a c++ project.
I get an error that mutex.h is missing.
1) Where in linux in read hat all include are ?
2) Where do I include it in eclispe ?
Spasiva
You don't mention which type of mutex you are trying to use:
If it's the pthread mutex, then:
#include <pthread.h>
If it's the C++11 mutex, then:
#include <mutex>
(you'll also need to compile with -std=c++11).
I am trying to compile a driver. Version of my kernel is 3.2.0-27-generic.
I left only includes that I need:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/pci.h>
#include <linux/delay.h>
#include <linux/dmi.h>
These headers are found. But when I try to compile I get error that asm/cache.h file is not found.
When I dug dipper I found that there is no such folder as "asm", but asm-generic and it contains required headers.
It's structure of folder with headers:
Why was it renamed? Because of it I can't compile another drivers. If I rename "asm-geneic "to "asm" it will lead to other missing headers. What's wrong here?
asm/cache.h is architecture dependent, there are different asm directory for different architectures
arch/powerpc/include/asm/
arch/x86/include/asm/
arch/arm/include/asm
[...]
You can't rename include/asm-generic to include/asm because your problem is that you can't reach the architecture asm folder. Try to check your .config file or set manually the ARCH variable.