# Cannot find sys/param.h



## prypiat (Mar 1, 2014)

I am reading the FreeBSD Device Drivers book.  The first example is hello.c. But, When I am compiling it, it says

```
hello.c:1:10: fatal error: 'sys/param.h' file not found
```

hello.c:

```
#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:

```
KMOD= hello
SRCS= hello.c

.include <bsd.kmod.mk>
```

Thanks a lot.


----------



## ShelLuser (Mar 1, 2014)

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.


----------



## prypiat (Mar 1, 2014)

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`

```
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 

```
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.
```

*I*f 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.


----------



## ShelLuser (Mar 1, 2014)

I just tried this myself using my FreeBSD 10 test environment (i386) and I get the same two errors:


```
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.


----------



## prypiat (Mar 1, 2014)

ShelLuser said:
			
		

> Just tried this myself using my FreeBSD 10 test environment (i386) and I get the same 2 errors:
> 
> 
> ```
> ...



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


```
[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.


----------



## ljboiler (Mar 1, 2014)

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:
	
	



```
#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);
```


----------



## prypiat (Mar 2, 2014)

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.


----------

