Cannot find sys/param.h

I am reading the FreeBSD Device Drivers book. The first example is hello.c. But, When I am compiling it, it says
Code:
hello.c:1:10: fatal error: 'sys/param.h' file not found

hello.c:
Code:
#include <sys/param.h>
#include <sys/module.h>
#include <sys/kernel.h>
#include <sys/systm.h>

static int
hello_modevent(module_t mod __unused, int event, void *arg __unused)
{
    int error = 0;
    switch (event) {
    case MOD_LOAD:
	    uprintf("Hello, world\n");
    case MOD_UNLOAD:
	   uprintf("GoodBye, cruel world");
    default:
	   error = EOPNETSUPP;
    }

    return (error);
}

static moduledata_t hello_mod = {
	"hello",
	hello_modevent,
	NULL
}

DECLARE_MODULE(hello, hello_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);

Makefile:
Code:
KMOD= hello
SRCS= hello.c

.include <bsd.kmod.mk>

Thanks a lot.
 
What FreeBSD version are you using and have you perhaps made any specific changes to the base system yourself?

Because if I try to compile this program (using Clang on FreeBSD 9.2) then I get two errors, but none of them involve param.h.
 
ShelLuser said:
What FreeBSD version are you using and have you perhaps made any specific changes to the base system yourself?

Because if I try to compile this program (using Clang on FreeBSD 9.2) then I get two errors, but none of them involve param.h.

uname -a
Code:
FreeBSD FreeBSD-1 10.0-RELEASE FreeBSD 10.0-RELEASE #0 r260789: Fri Jan 17 01:46:25 UTC 2014     root@snap.freebsd.org:/usr/obj/usr/src/sys/GENERIC  i386

I did not modify the system except installing X.Org and Emacs. And after I type make, the system displays
Code:
make
Warning: Object directory not changed from original /usr/home/user/Workplaces/hello
cc -O2 -pipe -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -I. -I@ -I@/contrib/altq -fno-common   -mno-aes -mno-avx -mno-mmx -mno-sse -msoft-float -ffreestanding -fstack-protector -std=iso9899:1999 -Qunused-arguments -fstack-protector -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes  -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual  -Wundef -Wno-pointer-sign -fformat-extensions  -Wmissing-include-dirs -fdiagnostics-show-option  -Wno-error-tautological-compare -Wno-error-empty-body  -Wno-error-parentheses-equality  -c hello.c
hello.c:1:10: fatal error: 'sys/param.h' file not found
#include <sys/param.h>
         ^
1 error generated.
*** Error code 1

Stop.

If I want to build a kernel module, is it for me to install some extra library? I checked my /usr/local/include/sys. These files are existing.
 
I just tried this myself using my FreeBSD 10 test environment (i386) and I get the same two errors:

Code:
hello.c:16:19: error: use of undeclared identifier 'EOPNETSUPP'
          error = EOPNETSUPP;
                  ^
hello.c:26:6: error: expected ';' after top level declarator
    }
     ^
     ;
2 errors generated.
*** Error code 1
Both environments (the 9.2 (amd64) VPS server and this 10.0 virtual test environment) have been built and customized using the source tree and also use a customized kernel. Needless to say but both also have the source tree available on /usr/src, I have no idea but perhaps that could be of influence.

One thing though; you shouldn't be looking at /usr/local for those files since these are system files, thus provided by the base system itself. param.h for example can be found in /usr/include/sys.
 
ShelLuser said:
Just tried this myself using my FreeBSD 10 test environment (i386) and I get the same 2 errors:

Code:
hello.c:16:19: error: use of undeclared identifier 'EOPNETSUPP'
          error = EOPNETSUPP;
                  ^
hello.c:26:6: error: expected ';' after top level declarator
    }
     ^
     ;
2 errors generated.
*** Error code 1
Both environments (the 9.2 (amd64) VPS server and this 10.0 virtual test environment) have been build and customized using the source tree and also use a customized kernel. Needless to say but both also have the source tree available on /usr/src, I have no idea but perhaps that could be of influence.

One thing though; you shouldn't be looking at /usr/local for those files since these are system files, thus provided by the base system itself. param.h for example can be found in /usr/include/sys.

I find param.h at /usr/src/XXX and /usr/include/sys.

Code:
[user@FreeBSD-1 /usr/include/sys]$ ls param.h 
param.h

And I can build a custom kernel by following https://www.freebsd.org/doc/handbook/kernelconfig.html. What else should I check? Thanks.
 
You might have something in /etc/src.conf or /etc/make.conf that is causing this error. EOPNETSUPP should be EOPNOTSUPP, you need a semicolon after "}" on the hello_mod structure, and you probably should put "break;" lines in your switch statement:
Code:
#include <sys/param.h>
#include <sys/module.h>
#include <sys/kernel.h>
#include <sys/systm.h>

static int
hello_modevent(module_t mod __unused, int event, void *arg __unused)
{
  int error = 0;
  switch (event) {
    case MOD_LOAD:
      uprintf("Hello, world\n");
      break;
    case MOD_UNLOAD:
      uprintf("GoodBye, cruel world");
      break;
    default:
      error = EOPNOTSUPP;
  }
  return (error);
}

static moduledata_t hello_mod = {
  "hello",
  hello_modevent,
  NULL
};

DECLARE_MODULE(hello, hello_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
 
I didn't change any thing except recompiling the kernel. The problem has been settled, though I do not know the reason. Thanks for debugging my codes.
 
Back
Top