Where do I place a C library for use on Windows, M

2019-07-29 06:47发布

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.

2条回答
等我变得足够好
2楼-- · 2019-07-29 07:15

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

查看更多
ゆ 、 Hurt°
3楼-- · 2019-07-29 07:39

@ Linux:

  • /usr/lib path's for dynamic libraries (.so)
  • /usr/include path's for libraries headers (.h)

/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:

gcc -o <src_program_app> -I/usr/local/include/<ur_library_dir> <src_program>.c

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.

查看更多
登录 后发表回答