简体   繁体   中英

Error : LNK1104 cannot open file 'pthread.lib'

I am trying to compile a native Linux C++ application in Windows using Visual Studio 2017. The app uses WebRtc's Acoustic Echo Cancellation(AEC) APIs to negate echo on wav files. Following is the CmakeLists.txt file:

cmake_minimum_required(VERSION 2.8)
project(wav-aec)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
add_subdirectory(gflags)
add_definitions("-DWEBRTC_NS_FLOAT -DWEBRTC_WIN -DNOMINMAX")

#-DWEBRTC_UNTRUSTED_DELAY -DWEBRTC_LINUX -DWEBRTC_POSIX 

include_directories(
    webrtc
    webrtc/webrtc/common_audio/signal_processing/include
    webrtc/webrtc/modules/audio_coding/codecs/isac/main/include
)

set(WEBRTC_SRC_
    base/buffer.cc
    base/checks.cc
    ...
    ...
    #system_wrappers/source/rw_lock_posix.cc
    system_wrappers/source/trace_impl.cc
    #system_wrappers/source/trace_posix.cc
)

function(prepend_path var prefix)
   set(listVar "")
   foreach(f ${ARGN})
      list(APPEND listVar "${prefix}/${f}")
   endforeach(f)
   set(${var} "${listVar}" PARENT_SCOPE)
endfunction(prepend_path)

prepend_path(WEBRTC_SRC webrtc/webrtc ${WEBRTC_SRC_})

add_executable(webrtc-audioproc webrtc-audioproc.cpp ${WEBRTC_SRC})
target_link_libraries(webrtc-audioproc gflags pthread)

When I try to build it, I get the following errror: Error: LNK1104 cannot open file 'pthread.lib'

Here is the link to the only linux dependent source file(cpp) of the project: https://github.com/lschilli/wav-aec/blob/master/webrtc-audioproc.cpp

What will be the right approach to port the code from Linux to windows? Whats is Windows equivalent of gflags and pthread? And what necessary changes needs to go to CmakeLists.txt?

PS: I have already added pthread header, dll and libs to Visual Studio directory manually.

If 'missing pthread library' is the only error, you can use pthread-w32 . We have successfully used it in some of our cross-platform apps requiring pthread.

They have libraries for both 64-bit and 32-bit. You can download and add it into your project. You haven't mentioned your toolset - their libraries are named differently depending on your toolset (MSVC or GNU) so you need to pick the right one. Check out their FAQ .

Hope it helps.

You need to us the actual lib file which is typically not "pthread.lib". It's most likely "pthreadVC3.lib" or "pthreadVC2.lib". Find the actual name by looking in the lib directory of your source package. You might see other lib files in there like "pthreadVCE3.lib" and "pthreadVSE3.lib", but you want to link "pthreadVC3.lib".

You can either add this in the project settings, or add the following code:

#pragma comment(lib,"pthreadVC3.lib")

To add it to the project settings:

  • Go to project properties->Configuration Properties->Linker->General and add your library path to Additional Library Directories
  • Go to project properties->Configuration Properties->Linker->Input and add the lib file (such as "pthreadVC3.lib") to Additional Dependencies

Make sure you have the correct version of pthread to match your compile settings, ie x86/x64.

In my case, I am using VCPkg for package management and I installed pthreads using the following commands:

vcpkg install pthread:x86-windows
vcpkg install pthread:x64-windows

And my package lib directory is "C:\vcpkg\installed\x64-windows\lib" I additionally had to add the following to my project settings as vcpkg wasn't integrating automatically:

  • Go to project properties->Configuration Properties->VC++ Directories and add "C:\vcpkg\installed\x64-windows\include" to Include Directories
  • Go to project properties->Configuration Properties->VC++ Directories and add "C:\vcpkg\installed\x64-windows\lib" to Library Directories

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM