Re: Default library and header search paths

From: Paul Procacci <pprocacci_at_gmail.com>
Date: Sun, 06 Jul 2025 08:13:10 UTC
On Sun, Jul 6, 2025 at 1:18 AM Eason Qin <eason@ezntek.com> wrote:
>
> Dear FreeBSD users,
>
> I have more of an ideological question.
>
> I'm a C programmer who's used FreeBSD once before, but not for
> programming (back in the freebsd 13.2 days); why are /usr/local/lib and
> /usr/local/include not in the default library and header search paths?
> If ports with headers and libraries are shipped with ports and theyre so
> ubiquitous, why must I manually specify these paths with every
> compilation I do involving a library? When I write on Linux, I simply
> have to just pass -lraylib (or such).
>
> I am aware I can mitigate this with pkg-config, but that feels slightly
> redundant at times (it is after all a port).
>
> Sincerely,
> Eason Qin
>
>

Well for one, linux is just a kernel.
The "other" stuff that ships from linux vendors is generally stuck in
a single folder (or two).  Hence the reason for not having to specify
any additional paths from those vendors.

FreeBSD on the other hand is much more than just a kernel; it's also
an entire userland.
FreeBSD installs libs not included in the base system into different
directories to maintain a clear separation between base system
components and third-party software.

This provides a plethora of benefits:
 - Ease of (down/up)grading the base OS without touching installed
third-party software
 - Ease of (down/up)grading third party software without touching base system.
 - As an extension to the two items above, installed header files
can't interfere with the base system.
 - .. and probably most importantly, follows the defined unix
hierarchical conventions established in 97' (I think it was -- open to
being corrected).  FreeBSD has splintered from this ever so slightly,
but it's darn close enough.

In contrast, Linux (and her distributors) have always been a "throw
spaghetti against the wall" type of ecosystem.... one giant folder!!
mwah hah hah

It's this difference, this modular approach that FreeBSD takes, that
is the root of the "why" here.
If you're just compiling C programs, the simple approach is to set an
environment variable via your login shell:  C_INCLUDE_PATH   (CPATH
can work too)
For libs, just add /usr/local/lib to /etc/ld.so.conf.d/local.conf and
run ldconfig.

Ultimately though, when I program in C on FreeBSD which is like nearly
all programming I do, my build system (make(1) for me), already has
everything defined.

~Paul

-- 
__________________

:(){ :|:& };: