C linux includes

I'm reading The Linux Programming Interface and have downloaded the sample code. A lot of it won't compile as the author said it would maybe have problems compile under another variant of UNIX (I'm using FreeBSD 11.1). My question is is it possible to somehow install the header files that aren't being found?
 
Please post short examples or sniplets that show the problem. Judging by the description of the book, and by the table of contents, the book teaches normal user-space programming techniques, which should not be Linux-specific, but should work using standard Unix (perhaps SUS or POSIX) interfaces. In that case, it should be easy to adjust the sample code to compile on any Unix system (or any SUS- or POSIX-compliant system).

I just looked at two of the three chapters of the book that are freely downloadable, and they are completely not Linux-specific, and should work on any standard Unix, including *BSD. Matter-of-fact, I wonder why the author named his book "the *Linux* programming interface", if most of it talks about Unix or POSIX, not specifically Linux.

It may also be possible to install some package that includes the Linux header files, perhaps some of the Linux ABI compatibility layer. Not my area of expertise.
 
There's the devel/linux-c7-devtools port that might allow simple command line programs to be compiled. Though from the occasions when I referred to this book at work, I tend to agree with ralphbsz that it should be possible to run many of the programs on FreeBSD as well. I certainly used it to look up information for programs that need to run on various UNIX incarnations. Though the book also mentions non-portable extensions that will not compile on FreeBSD.
 
The source directory has sample Makefile.inc files. I copied the Makefile.inc.FreeBSD to Makefile.inc and still had little milage. Thanks for your help.
 
The following worked for me: Extracted what's labeled as the Distribution Version into tmp, resulting in tmp/tlpi-dist. As you wrote, replaced Makefile.inc by Makefile.inc.FreeBSD. Then changed into tmp/tlpi-dist/lib and ran make which completed without error. Changed back to tmp/tlpi-dist and ran make -k allgen. I think allgen is a target that should compile mostly samples that are supposed to work across platforms. The -k option tells make to continue after errors. This compiled many source files without error (some gave errors, though) and wrote a bunch of binaries to the sub-folders for the individual topics. Tested a select few of them, they seem to work fine.
 
If most of them actually "work" (mean compile, link run), it would actually be very instructive to fix the few that don't work; that would teach one a lot about real-world portability.
 
Back
Top