Reputation: 3
I've encountered a perplexing issue while compiling a program. Despite having the stdio.h file in /usr/include and compiling with the gcc command without errors, I still encounter the following error when executing the make command:
fatal error: stdio.h: No such file or directory
I've already executed
sudo apt-get install libc6-dev
so I'm puzzled as to why this error persists. Any insights or suggestions would be greatly appreciated. Thank you!
program:
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
int main() {
Display *display;
Window root_window;
XEvent event;
// Open display connection
display = XOpenDisplay(NULL);
if (display == NULL) {
fprintf(stderr, "Unable to open display connection\n");
return 1;
}
// Get the root window
root_window = XRootWindow(display, DefaultScreen(display));
// Listen for mouse button events
XGrabButton(display, AnyButton, AnyModifier, root_window, True,
ButtonPressMask | ButtonReleaseMask, GrabModeSync, GrabModeAsync,
None, None);
printf("Intercepting mouse events...\n");
// Enter event loop
while (1) {
XNextEvent(display, &event);
if (event.type == ButtonPress) {
printf("Mouse button press event intercepted\n");
// Add your handling logic here
} else if (event.type == ButtonRelease) {
printf("Mouse button release event intercepted\n");
// Add your handling logic here
}
}
// Close display connection
XCloseDisplay(display);
return 0;
}
Makefile:
obj-m += program2.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules EXTRA_LDFLAGS="-L/usr/lib -lX11"
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
I hope to run the 'make' command without encountering any errors.
Upvotes: 0
Views: 75
Reputation: 141748
Any insights or suggestions would be greatly appreciated
You have a Makefile for building a Linux kernel module. In linux kernel there is no stdio, or X and there is no /usr/include.
I suggest removing the Makefile file.
I hope to run the 'make' command without encountering any error
Then write a new one for compiling your program. It might look like:
program2: program2.c
gcc ./program2.c -lX11 -o program2
Make is a grandpa with 50 years. Consider using a build system, like CMake.
Upvotes: 0