I have looked at a few places to figure out where to place the file on Macs, and it seems that placing them into /usr/lib/libmylib.dylib
and /usr/include/mylib.h
is the correct place, rather than either in the HOME directory, or in /usr/local/lib
. (This is for something the user installs on their computer).
Please let me know if that is correct.
Then the rest of my question is where is the equivalent (i.e. best) place to place a C lib on windows and linux. Looking here for windows says either %windir%\system32
or %SystemRoot%\winsxs
. But then they go about seemingly saying that it's still a bad place to put it for several reasons. So I'm not sure there.
Then the rest is how to do it for Linux. Seems to be the same as on Mac.
The end goal is so someone can simply do #include <mylib.h>
in their C code and get it to work.
It depends on which versions of macOS you're using.
For a Mac, you won't be able to place libraries in
/usr/lib
or headers in/usr/include
under macOS since Apple added 'System Integrity Protection' (SIP) to macOS 10.11 El Capitan (circa October 2015). You will need to use/usr/local/lib
or maybe somewhere under/opt
.You then need to determine whether your C compiler is configured to look for headers in
/usr/local/include
and libraries in/usr/local/lib
by default. If it isn't, then you'll need to add-I /usr/local/include
and-L /usr/local/lib
to the command line. (If you place your library under/opt
, you'll definitely need comparable options with the appropriate value.)You can find some relevant links in Can Mac OS X El Capitan run software compiled for Yosemite that expects libraries in /usr/gnu64/lib? The answer to the headline question of that link is "No, it can't".
@ Linux:
/usr/local/include it's a path prefix for user programs not managed by the distribution. You will want to indicate this path to C compiler in order to find libraries. Your command it's like this:
Where src_program.c has the import of library found on ur_library_dir.
However, you can later go try a Build System like Cmake which automates this compiling.