windows 你如何为 x64 编译静态 pthread-win32 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/159298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you compile static pthread-win32 lib for x64?
提问by kgriffs
It looks like some work has been done to make pthread-win32work with x64, but there are no build instructions. I have tried simly building with the Visual Studio x64 Cross Tools Command Prompt, but when I try to link to the lib from an x64 application, it can't see any of the function exports. It seems like it is still compiling the lib as x86 or something.
看起来已经做了一些工作来使pthread-win32与 x64 一起工作,但是没有构建说明。我曾尝试使用 Visual Studio x64 交叉工具命令提示符进行简单的构建,但是当我尝试从 x64 应用程序链接到 lib 时,它看不到任何函数导出。似乎它仍在将 lib 编译为 x86 或其他东西。
I've even tried adding /MACHINE to the makefile in the appropriate places, but it doesn't help. Has anyone gotten this to work?
我什至尝试在适当的位置将 /MACHINE 添加到 makefile 中,但它没有帮助。有没有人让这个工作?
采纳答案by kgriffs
Until it's officially released, it looks like you have to check out the CVS head to get version 2.9 of the library. Version 2.9 has all the x64 patches, but you will still have problems if you try to compile the static library from the command line.
在正式发布之前,看来您必须查看 CVS 头才能获得该库的 2.9 版。2.9 版包含所有 x64 补丁,但如果您尝试从命令行编译静态库,您仍然会遇到问题。
The only workaround I know of is to use the DLLs instead of statically linking the LIB.
我知道的唯一解决方法是使用 DLL 而不是静态链接 LIB。
回答by rogerdpack
For me, I just use a 64-bit windows compiler (mingw-w64 cross compiler in this particular case) then make (with2.9.1) like:
对我来说,我只使用 64 位 Windows 编译器(在这种特殊情况下是 mingw-w64 交叉编译器),然后 make (with2.9.1) 像:
$ make clean GC-static
Then how I install it for use (some of this may not be needed, of course),
然后我如何安装它以供使用(当然,其中一些可能不需要),
cp libpthreadGC2.a $mingw_w64_x86_64_prefix/lib/libpthread.a
cp pthread.h sched.h semaphore.h $mingw_w64_x86_64_prefix/include
then to use it, you have to define this (example ffmpeg configure line to use it):
然后要使用它,您必须定义它(示例 ffmpeg 配置行以使用它):
--extra-cflags=-DPTW32_STATIC_LIB
Anyhow that's one way.
无论如何,这是一种方式。
Another way is to do the same then modify the *.h files and remove all references to dllexport from the headers (or manually define DPTW32_STATIC_LIB in the headers).
另一种方法是执行相同的操作,然后修改 *.h 文件并从头文件中删除对 dllexport 的所有引用(或在头文件中手动定义 DPTW32_STATIC_LIB)。
ex:
前任:
sed 's/ __declspec (dllexport)//g;s/ __declspec (dllimport)//g'
(ref: zeranoe build scripts)
(参考:zeranoe 构建脚本)
回答by user3726672
Here's how I did it (VS2015). Should work for older Visual Studios too.
这是我的做法(VS2015)。也应该适用于较旧的 Visual Studio。
1) Download the release .zip from SourceForge
2) Unpack to a clean folder- should see "pthreads.2"
3) Open up your Visual Studio command prompt, navigate to "pthreads.2."
4) Run "nmake", no arguments. It produces a help message listing all the legal commands you can give 'nmake' to build it. For more info, see "pthreads.2\FAQ" file which explains their 3 different flavors of 'cleanup' handling.
1) 从 SourceForge 下载发行版 .zip
2) 解压到一个干净的文件夹 - 应该看到“pthreads.2”
3) 打开你的 Visual Studio 命令提示符,导航到“pthreads.2”。4)运行“nmake”,没有参数。它会生成一条帮助消息,列出您可以使用“nmake”来构建它的所有合法命令。有关更多信息,请参阅“pthreads.2\FAQ”文件,该文件解释了它们 3 种不同风格的“清理”处理。
I would suggest building "VC" and "VC-debug" (and maybe the static ones of those) only. The 'real' pthreads is a C system library on POSIX platforms like Linux, so only those combos are going to give you the exact same C error behavior on Windows that you'd get on Linux, FreeBSD, etc.
我建议只构建“VC”和“VC-debug”(也许是静态的)。“真正的”pthreads 是 Linux 等 POSIX 平台上的 C 系统库,因此只有这些组合才能在 Windows 上为您提供与在 Linux、FreeBSD 等上完全相同的 C 错误行为。
回答by Vladimir Fekete
to expand kgriffs answer one has to do two more things to actually build a 64bit DLL and not 32bit DLL.
要扩展 kgriffs 答案,必须再做两件事才能实际构建 64 位 DLL 而不是 32 位 DLL。
First download latest pthreads via CVS (as suggested here)
通过CVS首先下载最新的并行线程(如建议在这里)
1) use 64bit build tools - achieved by loading correct VC environment settings in command line (more about it here):
1) 使用 64 位构建工具 - 通过在命令行中加载正确的 VC 环境设置来实现(更多关于这里):
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat amd64
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat amd64
(change the 11.0 to whatever version you are using)
(将 11.0 更改为您使用的任何版本)
2) As it is written in the pthreads Makefile:
2) 正如 pthreads Makefile 中所写:
TARGET_CPU is an environment variable set by Visual Studio Command Prompt as provided by the SDK (VS 2010 Express plus SDK 7.1) PLATFORM is an environment variable that may be set in the VS 2013 Express x64 cross development environment
TARGET_CPU是SDK(VS 2010 Express加SDK 7.1)提供的Visual Studio Command Prompt设置的环境变量PLATFORM是VS 2013 Express x64交叉开发环境中可能设置的环境变量
which means, that if it was not done by the vcvars (in my case it wasn't) you need to set TARGET_CPU or PLATFORM (just in case I set them both):
这意味着,如果它不是由 vcvars 完成的(在我的情况下不是),您需要设置 TARGET_CPU 或 PLATFORM (以防万一我同时设置它们):
set TARGET_CPU=x64
set PLATFORM=x64
set TARGET_CPU=x64
set PLATFORM=x64
3) and now the final step:
3)现在是最后一步:
nmake clean VC
nmake clean VC-debug
nmake clean VC
nmake clean VC-debug
this will make a 64bit DLL files (and proper import library and PDB). I can verify that it works with Visual Studio 2012.
这将生成 64 位 DLL 文件(以及适当的导入库和 PDB)。我可以验证它是否适用于 Visual Studio 2012。
回答by Head Geek
This messagemight help.
此消息可能会有所帮助。