Windows 上的/usr/lib/相当于什么? [英] What is the equivalent of /usr/lib/ on Windows?

查看:38
本文介绍了Windows 上的/usr/lib/相当于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个依赖于 libxml2 的跨平台程序.我不想在应用程序的 Windows 端口上使用 POSIX 环境,例如 Cygwin 或 MSYS.我计划使用 Javascript Host for Windows 和 nmake 创建一个构建脚本系统.但是,出现了构建系统应该在哪里寻找 libxml2 的问题.当用户没有指定位置时,它应该在哪些位置查看?在 Linux 上,它通常是/usr/lib/和/usr/local/lib/.但是在 Windows 上,唯一想到的地方是 C:\Windows\system32.但是那个目录不是只能被系统修改吗?(我显然对 Windows 的内部结构几乎一无所知)

I am creating a cross-platform program that depends on libxml2. I do not want to use a POSIX environment such as Cygwin or MSYS on the Windows port of the app. I am planning to create a system of build scripts using Javascript Host for Windows and nmake. But, the question arose of where the build system should look for libxml2. In what locations should it look when the user does not specify a location? On Linux, it is usually /usr/lib/ and /usr/local/lib/. But on Windows, the only place that comes to mind is C:\Windows\system32. But isn't that directory only modified by the system? (I obviously know next to nothing about the internals of Windows)

推荐答案

/usr/lib/ 在 Windows 中真正的等价物实际上是 %windir%\system32,因为它是 总是(最后)Windows 查找 DLL 的地方.

The true equivalent of /usr/lib/ in Windows really is %windir%\system32, as it is always the (last) place where Windows looks for DLLs.

但简单地转储你的库是 DLL Hell 之所以存在的部分原因.这就是为什么引入 COM 系统的原因;如果您的 DLL 是 COM 类的服务器模块",您可以注册它(例如通过 regsvr32 实用程序),之后应用程序可以通过 CoCreateInstance() 函数.在这里,注册表服务于 /usr/lib/ 的目的,但完全不同.

But simply dumping your libraries there is part of why DLL Hell is a thing. This is why the COM system was introduced; if your DLL is a "server module" for COM classes, you can register it (for instance through the regsvr32 utility), after which applications can dynamically link with its served classes through the CoCreateInstance() function. Here, the registry serves the purpose of /usr/lib/, but is completely different.

在现代 Windows 版本中,(注册-免费)并行程序集.事实上,有时需要明确取消程序集的注册才能很好地使用这个新系统.从这个意义上说,%SystemRoot%\winsxs 相当于 /usr/lib/,但方式更复杂.

In modern Windows versions, the need for explicit registration is no longer needed with (registration-free) side-by-side assemblies. In fact, explicit deregistration of assemblies is sometimes needed to play nice with this new system. In this sense, %SystemRoot%\winsxs is the equivalent of /usr/lib/, but in an even more convoluted way.

由于这种混乱,您的潜在问题的答案 ---我应该在哪里寻找 libxml2?"--- 就是你找不到它".与为模块化设计的操作系统不同,您通常不会在 Windows 上安装单独的库.如果您想针对 libxml2 进行构建,您可以将 .lib 文件与您的源代码捆绑在一起,或者告诉用户提供它.如果要部署构建,请将 libxml2 与应用程序一起部署(静态链接,或作为应用程序目录中的 DLL).

Because of this mess, the answer to your underlying question --- "where should I look for libxml2?" --- is that "you won't find it". Unlike the operating systems that were made for modularity, you usually don't install separate libraries on Windows. If you want to build against libxml2, you either bundle the .lib file with your source, or tell the user to provide it. If you want to deploy a build, you deploy libxml2 along with your application (either statically linked, or as a DLL inside the application directory).

即使它是在系统范围内安装的,因为 libxml2 并没有考虑到特定于 Windows 的概念,所以唯一可以找到它的地方是 %windir%\system32.不过,没有人敢把它放在那里.

And even if it were installed system-wide, since libxml2 isn't made with Windows-specific concepts in mind, the only place to find it would be %windir%\system32. Nobody has the gall to place it there, though.

注意:我不是很精通 COM 和 .NET,因此上述内容可能不完全准确.如果有人想改进这个答案,我愿意把它变成一个社区维基.

这篇关于Windows 上的/usr/lib/相当于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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