c++ - 你如何为 x64 编译静态 pthread-win32 库?

标签 c++ c windows 64-bit pthreads

看起来已经做了一些工作来制作pthread-win32使用 x64,但没有构建说明。我曾尝试使用 Visual Studio x64 交叉工具命令提示进行简单构建,但是当我尝试从 x64 应用程序链接到 lib 时,它看不到任何函数导出。它似乎仍在将 lib 编译为 x86 或其他东西。

我什至尝试过将/MACHINE 添加到 makefile 的适当位置,但没有帮助。有人让这个工作吗?

最佳答案

您可以使用vcpkg here .这是 C++ 的 Windows 包管理器。 它支持 pthread 构建以及其他开源库。

我想使用静态 pthread 库。 当我下载 pthread 时,我得到了 dll(pthread.dll) 并导入了 lib(pthread.lib),即我不能只使用 pthread.lib,我不得不使用 pthread.dll 文件。

所以我使用 vcpkg 构建了静态库。我可以在没有任何 dll 依赖的情况下使用它

使用“vcpkg”你可以构建静态库和动态库

您可以使用以下步骤

下面我添加了所有 DLL (x86|x64) 和 LIB (x86|x64) 案例的步骤。您可以根据需要构建它。

从 git 目录中克隆 vcpkg vcpkg git repo

从您克隆 vcpkg 的目录运行下面的命令-这将安装 vcpkg

bootstrap - vcpkg.bat

通过运行以下命令检查库的可用性

vcpkg search pthread

下面会显示结果

mbedtls[pthreads]                     Multi-threading support
pthread              3.0.0            empty package, linking to other port
pthreads             3.0.0-6          pthreads for windows

如你所见,它支持 windows 的 pthread

1.使用导入库(DLL)构建动态库

构建 x86 DLL

vcpkg install pthreads:x86-windows

这将在 .\vcpkg\installed\x86-windows 中构建 dll 和导入库 这里复制libinclude,你可以使用它们

构建 x64 DLL

vcpkg install pthreads:x64-windows

这将在 .\vcpkg\installed\x64-windows 中构建 dll 和导入库 在这里复制 libinclude 文件夹。

<强>2。构建静态库 (LIB)

构建 x86 LIB

vcpkg install pthreads:x86-windows-static 

这将在 .\vcpkg\installed\x86-windows-static 中构建 dll 和导入库 从这里复制 libinclude 然后你就可以使用它们了

构建 x64 LIB

vcpkg install pthreads:x64-windows-static

这将在 .\vcpkg\installed\x64-windows-static 中构建 dll 和导入库 从这里复制 libinclude 文件夹。

注意:尝试使用管理员权限

关于c++ - 你如何为 x64 编译静态 pthread-win32 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/159298/

相关文章:

c - 在 C 语言中检测 switch case 内的 Enter?

java - 在 Windows、OSX 和 Linux 上获取进程的 PID

c# - 在 Windows Mobile 应用程序中存储应用程序设置的首选方法是什么?

模板内部类中的 C++ decltype

c - 如何在 c 中分配大容量(GB 数量级)的内存?

c++ - std shared_pointer_cast 未定义

c - 努力按整数搜索文件中的结构数组

c# - 如何存储程序设置?

c++ - 为不同命名空间中的类专门化模板函数

c++ - 当我们在 qt 中关闭一个窗口时发出的信号是什么