jeremycw / httpserver.h

Single header library for writing non-blocking HTTP servers in C
MIT License
1.78k stars 143 forks source link

"fatal error: sys/event.h: No such file or directory" #71

Open ssleert opened 9 months ago

ssleert commented 9 months ago

When i trying to compile this code with gcc main.c

#define HTTPSERVER_IMPL
#include "httpserver.h"

#define RESPONSE "Hello, World!"

void handle_request(struct http_request_s* request) {
  struct http_response_s* response = http_response_init();
  http_response_status(response, 200);
  http_response_header(response, "Content-Type", "text/plain");
  http_response_body(response, RESPONSE, sizeof(RESPONSE) - 1);
  http_respond(request, response);
}

int main() {
  struct http_server_s* server = http_server_init(8080, handle_request);
  http_server_listen(server);
}

I got this error

In file included from main.c:2:
common.h:38:3: error: unknown type name ‘epoll_cb_t’
common.h:91:3: error: unknown type name ‘epoll_cb_t’
common.h:92:3: error: unknown type name ‘epoll_cb_t’
common.h:112:3: error: unknown type name ‘epoll_cb_t’
common.h:113:3: error: unknown type name ‘epoll_cb_t’
server.c:14:10: fatal error: sys/event.h: No such file or direct
compilation terminated.

Info about system

$ gcc --version
gcc (GCC) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ uname -a
Linux s2me 6.5.8-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Oct 20 15:53:48 UTC 2023 x86_64 GNU/Linux

$ cat /etc/os-release 
NAME="Fedora Linux"
VERSION="38.20231101.0 (Silverblue)"
ID=fedora
VERSION_ID=38
VERSION_CODENAME=""
PLATFORM_ID="platform:f38"
PRETTY_NAME="Fedora Linux 38.20231101.0 (Silverblue)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:38"
DEFAULT_HOSTNAME="fedora"
HOME_URL="https://silverblue.fedoraproject.org"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora-silverblue/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://github.com/fedora-silverblue/issue-tracker/issues"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=38
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=38
SUPPORT_END=2024-05-14
VARIANT="Silverblue"
VARIANT_ID=silverblue
OSTREE_VERSION='38.20231101.0'

gcc installed through rpm-ostree

Yasha-ops commented 9 months ago

I have the same issue. Can someone help ? @ssleert

ssleert commented 9 months ago

I have the same issue. Can someone help ? @ssleert

add this before include

#define EPOLL
#import "httpserver.h"

and on linux it should work

ssleert commented 9 months ago

i can write simple pr that automatically define EPOLL on linux based environments