Building libtorrent-2.0.x for Windows.
Hi!
I want to build libtorrent from libtorrent-2.0.x with Visual Studio 2019 for Windows.
cmake reports for this is lacking in the library support pthread (Visual Studio does have it). Ok, I download it from, for example, here https://github.com/GerHobbelt/pthread-win32 Now cmake says that it does not find the definition of pthread_atfork. Really, Windows pthread implementation does not contain pthread_atfork support.
Maybe I'm doing something wrong?
Thanks for any help!
In your vckpg install command line, have you added this : pthread:x64-windows-static ?
In your vckpg install command line, have you added this : pthread:x64-windows-static ? Windows version of the pthread library has no pthread_atfork function support. pthread.h has no definition of pthread_atfork. How will the assembly parameters change this flaw? The error occurs at the time of compilation of test examples ("..\libtorrent-2.0.7\CMakeFiles\CMakeTmp\src.c").
I don't know, but, I've compiled libtorrent+qbittorent few weeks ago and it was working, the only stuff I needed to add was the pthread:x64-windows-static stuff.
I don't know, but, I've compiled libtorrent+qbittorent few weeks ago and it was working, the only stuff I needed to add was the pthread:x64-windows-static stuff. Thanks for your tip, maybe worth a try!
Let us know please !
I seem to be running out of patience for building this ill-fated library. I created a separate virtual machine with the latest installation packages (Win10x64, VC2019, cmake 3.20, pthread 3.0.0, libtorrent-2.0.7) for the virtual studio, but still here.
I can't get the linker to accept pthread libraries.
cl /c /I"D:\vcpkg\installed\x86-windows\include" /Zi /W1 /WX- /diagnostics:column /Od /Ob0 /Oy- /D CMAKE_HAVE_LIBC_PTHREAD /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_55100.dir\Debug\\" /Fd"cmTC_55100.dir\Debug\vc142.pdb" /external:W1 /Gd /TC /analyze- /errorReport:queue "D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\src.c"
src.obj : error LNK2019: unresolved external symbol _pthread_create referenced in function _main [D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\cmTC_55100.vcxproj]
src.obj : error LNK2019: unresolved external symbol _pthread_detach referenced in function _main [D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\cmTC_55100.vcxproj]
src.obj : error LNK2019: unresolved external symbol _pthread_exit referenced in function _main [D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\cmTC_55100.vcxproj]
src.obj : error LNK2019: unresolved external symbol _pthread_join referenced in function _main [D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\cmTC_55100.vcxproj]
src.obj : error LNK2019: unresolved external symbol _pthread_cancel referenced in function _main [D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\cmTC_55100.vcxproj]
src.obj : error LNK2019: unresolved external symbol _pthread_atfork referenced in function _main [D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\cmTC_55100.vcxproj]
D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\Debug\cmTC_55100.exe : fatal error LNK1120: 6 unresolved externals [D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\cmTC_55100.vcxproj]
@southernedge you can always look at the CI workflows for examples of how to build. (both github action and appveyor).
are you deliberately trying to link against libpthread on windows? That's a pretty unusual thing to do, especially with visual studio. I would expect that perhaps a mingw build might want to use libpthread, but not msvc.
Can you share what command line you're running to build?
is src.obj your translation unit? (I don't recognize it from libtorrent.
If so, it doesn't look like your problems have anything to do with libtorrent, you are trying to use libpthread but on the linker command line there's no mention of linking against it. What are you doing to ask the build system to link against libpthread?
Really, Windows pthread implementation does not contain pthread_atfork support.
probably because windows doesn't really spawn processes using a fork-like mechanism. If it's not absolutely required, I wouldn't recommend using libpthread on windows, with visual studio.
Why don't you just use the libtorrent part of this : https://github.com/qbittorrent/qBittorrent/wiki/Compilation:-Windows-(MSVC-2019,-64-bit,-static-linkage)
?
I've compiled again yesterday, it's working.
Really, Windows pthread implementation does not contain pthread_atfork support.
probably because windows doesn't really spawn processes using a fork-like mechanism. If it's not absolutely required, I wouldn't recommend using libpthread on windows, with visual studio.
Thank you for your answer!
I've been working for about 2-3 years with libtorrent-1_1_14. It works fine. I use it in a basic Visual Studio C++ project. That's why I need the final Visual Studio build. I can keep working with 1.1.14, but wanted to try and build a new 2.0.7.
Here's the build line. I didn't modify CMakeLists.txt file. pthreads was installed with help vcpkg.
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=14 -G "Visual Studio 16" -A Win32 -DCMAKE_C_FLAGS="/ID:/vcpkg/installed/x86-windows/include" -DCMAKE_EXE_LINKER_FLAGS="/LIBPATH:D:/vcpkg/installed/x86-windows/debug/lib"
Folder ../windows/debug/lib has next libs: pthreadVC3d.lib pthreadVCE3d.lib pthreadVSE3d.lib
The part of CMakeError.log
Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: D:/libtorrent-2.0.7/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/MSBuild/Current/Bin/MSBuild.exe cmTC_55100.vcxproj /p:Configuration=Debug /p:Platform=Win32 /p:VisualStudioVersion=16.0 /v:m && Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30146 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
src.c
cl /c /I"D:\vcpkg\installed\x86-windows\include" /Zi /W1 /WX- /diagnostics:column /Od /Ob0 /Oy- /D CMAKE_HAVE_LIBC_PTHREAD /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_55100.dir\Debug\\" /Fd"cmTC_55100.dir\Debug\vc142.pdb" /external:W1 /Gd /TC /analyze- /errorReport:queue "D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\src.c"
src.obj : error LNK2019: unresolved external symbol _pthread_create referenced in function _main [D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\cmTC_55100.vcxproj]
src.obj : error LNK2019: unresolved external symbol _pthread_detach referenced in function _main [D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\cmTC_55100.vcxproj]
src.obj : error LNK2019: unresolved external symbol _pthread_exit referenced in function _main [D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\cmTC_55100.vcxproj]
src.obj : error LNK2019: unresolved external symbol _pthread_join referenced in function _main [D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\cmTC_55100.vcxproj]
src.obj : error LNK2019: unresolved external symbol _pthread_cancel referenced in function _main [D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\cmTC_55100.vcxproj]
src.obj : error LNK2019: unresolved external symbol _pthread_atfork referenced in function _main [D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\cmTC_55100.vcxproj]
D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\Debug\cmTC_55100.exe : fatal error LNK1120: 6 unresolved externals [D:\libtorrent-2.0.7\CMakeFiles\CMakeTmp\cmTC_55100.vcxproj]
Source file was:
#include <pthread.h>
static void* test_func(void* data)
{
return data;
}
int main(void)
{
pthread_t thread;
pthread_create(&thread, NULL, test_func, NULL);
pthread_detach(thread);
pthread_cancel(thread);
pthread_join(thread, NULL);
pthread_atfork(NULL, NULL, NULL);
pthread_exit(NULL);
return 0;
}
There is no Windows pthread code in libtorrent+qbittorent.
click start, type x86 for x86 developer native tools command prompt
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -G "Visual Studio 16 2019" ..
zlib, openssl and boost are requirements.
To fix error you have above you have to specify pthreadV32.lib library file to linker or include via #pragma comment(lib, "pthreadV32.lib")
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.