如何在Windows中安装pkg-config?

89
10个回答

111

以下是一个逐步操作的过程,可以让您在Windows上使用pkg-config。这是基于我的经验,并结合了Oliver Zendel的评论信息。

在这里,我假设已将MinGW安装到C:\ MinGW。有多个版本的软件包可用,在每种情况下,我只需下载最新版本。

  1. 转到http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/
  2. 下载文件pkg-config_0.26-1_win32.zip
  3. 将bin / pkg-config.exe文件提取到C:\ MinGW \ bin
  4. 下载文件gettext-runtime_0.18.1.1-2_win32.zip
  5. 将bin / intl.dll文件提取到C:\ MinGW \ bin
  6. 转到http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.28
  7. 下载文件glib_2.28.8-1_win32.zip
  8. 将bin / libglib-2.0-0.dll文件提取到C:\ MinGW \ bin

现在,如果已配置使用MinGW,CMake将能够使用pkg-config。


4
如何将CMake更改为configure,以使用MinGW?如何将CMake更改为configure以使用MinGW? - cindywmiao
2
@cindywmiao:从生成器列表中选择一个带有MinGW名称的CMake生成器,例如“MinGW Makefiles”。我个人使用“CodeBlocks - MinGW Makefiles”,它还会为CodeBlocks IDE生成一个项目文件。 - HyperQuantum
3
你不必使用MinGW - 你可以按照这些步骤,但提取pk-config.exe和所需的DLL文件到任何你选择的文件夹(包括一个新文件夹),只要确保该文件夹在你的PATH中即可。 - yoyo
2
这很复杂。2021年是否有更新的答案?现在情况不同了。 - Yen Dang
如果有人需要它作为GitHub操作,可以在此处找到:https://gist.github.com/geoffreygarrett/06765936df5b4687d320491517ca5d47 - Geoffrey Garrett

65

18
我在那里也找到了需要的GTK二进制文件;对于pkg-config_0.26-1_win32.zip,你需要从http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.28/glib_2.28.8-1_win32.zip获取文件libglib-2.0-0.dll,以及从http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/gettext-runtime_0.18.1.1-2_win32.zip获取intl.dll文件。 - Oliver Zendel
7
我应该将这些文件放在哪里,才能让 cmake 找到它们? - JuJoDi
3
将它们放在 /bin 目录中,该目录应与 pkg-config 相对应。 - user472308
15
在Windows上,pkg-config会在哪里查找安装的库?它会去哪里搜索pc文件?这非常令人困惑,也是与此类垃圾软件有关的每个人都感到羞耻的原因... :) - Zordid
你没有提到把它们放在哪里。 - C.J.
1
将pkg-config可执行文件和依赖的DLL放置在路径上的任何文件夹中,例如C:\ WINDOWS。 - SmacL

59

一个没有依赖于glib的替代品是pkg-config-lite

从存档中提取pkg-config.exe并将其放入您的路径中。

现在,这个软件包可以使用chocolatey获取,然后可以通过以下方式安装:

choco install pkgconfiglite

运行良好,FAQ中列出的其他pkg-config在Windows 10 Home和Pro上也会崩溃。 - kumarharsh
你的路径是什么意思? - Yen Dang
将您提取可执行文件的目录添加到环境变量PATH中,以便访问它。 - mpromonet

6
我通过安装来实现这一点Cygwin64从这个链接https://www.cygwin.com/ 然后 - 查看完整版,搜索gcc并向下滚动以找到pkg-config。 单击图标选择最新版本。 这对我很有效。

5
我想扩展 @dzintars 关于 Cygwin 版本的 pkg-config 的答案,重点是如何正确地与 CMake 一起使用它,因为我在这个主题中看到了各种关于 CMake 的评论。
我在使用 CMake + Cygwin 的 pkg-config 时遇到了许多麻烦,我想分享一下如何避免它们的经验。
1. 符号链接 C:/Cygwin64/bin/pkg-config -> pkgconf.exe 在 Windows 控制台中不起作用。
它不是本地的 Windows .lnk 符号链接,即使您将“.;”添加到 %PATHEXT% 中(请参阅 https://www.mail-archive.com/cygwin@cygwin.com/msg104088.html),它也不能在 Windows 控制台 cmd.exe 中调用。
它在 CMake 中也无法工作,因为 CMake 使用 execute_process() 方法(FindPkgConfig.cmake)调用 pkg-config,该方法会打开一个新的 cmd.exe。
解决方案:在 CMake 命令行中添加 -DPKG_CONFIG_EXECUTABLE=C:/Cygwin64/bin/pkgconf.exe (或在 CMakeLists.txt 中设置)。

2. Cygwin的pkg-config仅识别PKG_CONFIG_PATH中的Cygwin路径(不支持Windows路径)。

例如,在我的系统上,.pc文件位于C:\ Cygwin64 \ usr \ x86_64-w64-mingw32 \ sys-root \ mingw \ lib \ pkgconfig。以下三个路径都是有效的,但只有路径C在PKG_CONFIG_PATH中起作用:

  • A)c:/ Cygwin64 / usr / x86_64-w64-mingw32 / sys-root / mingw / lib / pkgconfig-无法使用。
  • B)/ c / cygdrive / usr / x86_64-w64-mingw32 / sys-root / mingw / lib / pkgconfig-无法使用。
  • C)/ usr / x86_64-w64-mingw32 / sys-root / mingw / lib / pkgconfig-有效。

解决方案:将.pc文件位置始终作为Cygwin路径添加到PKG_CONFIG_PATH中。

3)CMake在Cygwin上将正斜杠转换为反斜杠。

由于https://gitlab.kitware.com/cmake/cmake/-/issues/21629的错误,会出现这种情况。这阻止了使用[2]中描述的解决方法。 解决方案:手动更新C:/Program Files/CMake/share/cmake-3.x/Modules/FindPkgConfig.cmake文件中的函数_pkg_set_path_internal()。注释或删除以下行:
file(TO_NATIVE_PATH "${_pkgconfig_path}" _pkgconfig_path)

4) CMAKE_PREFIX_PATH、CMAKE_FRAMEWORK_PATH和CMAKE_APPBUNDLE_PATH在Cygwin中对pkg-config无效。

原因:该问题https://gitlab.kitware.com/cmake/cmake/-/issues/21775

解决方案:如果您在Cygwin上运行CMake构建,请仅使用PKG_CONFIG_PATH作为环境变量。忘记CMAKE_PREFIX_PATH、CMAKE_FRAMEWORK_PATH和CMAKE_APPBUNDLE_PATH。


3
  1. https://sourceforge.net/projects/mingw-w64/下载并安装mingw64。避免在program files/(x86)文件夹中安装。例如,c:/mingw-w64。
  2. 这里下载pkg-config__win64.zip。
  3. 解压上述zip文件,并将pkg-config/bin文件夹中的所有文件复制粘贴到mingw-w64中。在我的情况下,它是'C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin'。
  4. 现在设置path = C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin,您就完成了。

如果您发现任何安全问题,请按以下步骤操作

  1. 在系统中搜索Windows Defender安全中心
  2. 导航到应用程序和浏览器控制>漏洞利用保护设置>程序设置>单击'+添加程序自定义'
  3. 选择按名称添加程序
  4. 输入程序名称:pkgconf.exe
  5. 确定
  6. 现在检查所有设置,将其设置为关闭并应用。

完成!


1
我喜欢taddaaa这个东西! - Imtiyaz Shaikh

0

来源:https://github.com/JoinMarket-Org/joinmarket/wiki/Installing-JoinMarket-on-Windows

本指南介绍如何在Windows上安装JoinMarket及其依赖项(python、libsodium、secp256k1)。

这些步骤可能适用于某些或所有版本的Windows,但也可能不适用。欢迎反馈报告。本指南并不保证完全无误,下载文件的验证需自行负责。

Install JoinMarket - go to https://github.com/JoinMarket-Org/joinmarket/releases and download the most recent release. Unzip it into any location you choose.

You will need to install MinGW from here or go to their website. After a few introductory screens, you will be shown a windows with some optional components that you have to choose; this basic setup is sufficient:

从左侧菜单中的"基本设置":

mingw-developer-toolkit
mingw32-base
mingw32-gcc-g++
msys-base

一旦您选择了这些内容,请从主菜单的第一项中选择“更新”。这些组件将安装到C:\MinGW\bin中。完成后,您应该在该文件夹C:\MinGW\bin中拥有此dll:libgcc_s_dw2-1.dll,以及许多其他文件;我特别提到此文件,因为它是此设置中libsecp256k1必需的。

接下来,您必须确保将C:\MinGW\bin添加到您的PATH变量中。以下是如何执行此操作的指南;在继续之前,您必须将;C:\MinGW\bin附加到路径末尾。

Install Python from https://www.python.org/ftp/python/2.7.11/python-2.7.11.msi. Run the executable. Choose to install the feature Add python.exe to Path (it's the last option in the installer, off by default - switch it on) on local hard drive during installation; Python should then be installed in C:\Python27 (EXTRA NOTE: the most recent 2.7 installation linked here seems to install pip automatically, which is very useful for step 4)

Check that Python runs. Open a new command prompt as administrator by typing cmd.exe into the Start menu and pressing Ctrl+Shift+Enter. Type python and you should see something like:

Python 2.7.11 (default....
....
>>>

使用exit()或按Ctrl+C退出Python控制台。现在,请确保您的pip版本是最新的:运行以下命令:python -m pip install --upgrade pip。

Go to the directory C:\Python27\Lib\distutils and add a new file, called distutils.cfg. Inside it, put:

[build]
compiler=mingw32

关闭并保存文件。
Next, you need to install the dll for libnacl. First go to https://download.libsodium.org/libsodium/releases/ and choose the file libsodium-1.0.4-msvc.zip to download. Unzip anywhere, and then copy the file libsodium.dll from the directory \Win32\Release\v120\dynamic (do not use v140), and paste it into root joinmarket directory (the same directory where README.md lives). Then you need to address the Visual C++ 2013 runtime dependency. Do so by going to www.microsoft.com/en-us/download/details.aspx?id=40784 and clicking Download. Choose x86 even on a 64-bit system, and run the executable.

Note that after doing this, you must run pip install -r requirements-windows.txt from the Joinmarket root directory (where the README.md file is) and should not get an error message (this will install/check the python packages libnacl and secp256k1(-transient)).

0

对于基于w64的计算机,您需要安装mingw64。如果缺少pkg-config.exe,则可以参考http://ftp.acc.umu.se/pub/gnome/binaries/win64/dependencies/

解压并将pkg-config.exe复制/合并到您的C:\ mingw-w64安装中,例如在我的PC上进入C:\ mingw-w64 \ x86_64-8.1.0-posix-seh-rt_v6-rev0 \ mingw64 \ bin


0

那个网站似乎有更新的版本,但你提供的版本已经过时了。软件包链接实际上是http://koji.fedoraproject.org/koji/packageinfo?packageID=13212。 - player_03
继我的先前评论之后:那些下载没有帮助;我用7-Zip提取了文件,但不知道下一步该怎么做。相反,我使用了以下网站上的说明,尽管它们要求使用不太更新的版本:http://www.gaia-gis.it/spatialite-3.0.0-BETA/mingw_how_to.html#pkg-config - player_03
3
该页面假定使用Mingw。但我在虚拟机中运行Visual Studio 2008,硬盘空间很少。我不想安装Mingw或Cygwin,只是为了能够运行pkg-config。缺少pkg-config是由cmake抛出的错误。我感到在这个混乱中迷失了方向。 - Jean-Denis Muys

0

在2022年,VS Code开箱即用支持CMake和pkgconfig(将pkgconfvcpkg-pkgconfig-get-modules 加入到您的vcpkg.json中)


你使用的pkgconf版本是哪个?能否提供.json文件的结构? - giammi56

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接