我在哪里放置可以在Windows,Mac和Linux上使用的C库 [英] Where do I place a C library for use on Windows, Mac, and Linux

查看:106
本文介绍了我在哪里放置可以在Windows,Mac和Linux上使用的C库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经查看了几个地方以找出文件在Mac上的放置位置,似乎将它们放置在/usr/lib/libmylib.dylib/usr/include/mylib.h中是正确的位置,而不是放在HOME目录中还是在/usr/local/lib. (这是用户在计算机上安装的东西.)

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

请让我知道是否正确.

然后我剩下的问题是在Windows和Linux上放置C库的等效位置(即 best )在哪里.在Windows的此处中查找%windir%\system32%SystemRoot%\winsxs.但是随后他们似乎在说,由于种种原因,放置它仍然是一个糟糕的地方.所以我不确定在那里.

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.

最终目标是使某人可以简单地在其C代码中执行#include <mylib.h>并使其正常工作.

The end goal is so someone can simply do #include <mylib.h> in their C code and get it to work.

推荐答案

@ Linux:

  • /usr/lib的动态库(.so)路径
  • 库标头(.h)的
  • /usr/include路径
  • /usr/lib path's for dynamic libraries (.so)
  • /usr/include path's for libraries headers (.h)

/usr/local/include是非发行版管理的用户程序的路径前缀.您将需要指示C编译器的此路径以查找库.您的命令是这样的:

/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

其中src_program.c导入了在ur_library_dir上找到的库.

Where src_program.c has the import of library found on ur_library_dir.

但是,您以后可以尝试使用像Cmake这样的构建系统来自动执行该编译.

However, you can later go try a Build System like Cmake which automates this compiling.

这篇关于我在哪里放置可以在Windows,Mac和Linux上使用的C库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆