Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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?

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

For pthreads, take a look at this answer: stackoverflow.com/a/2150957/1076479 I don't know enough to say for sure, but I suspect pthreads is only the tip of this iceberg. – Gil Hamilton Dec 12, 2018 at 23:54 It is not just a matter of compilers when you port a project from linux to windows. Thread s are a good example of what you need to change in your code. Look if you can find some define like WIN32 or LINUX inside your code, maybe who wrote it provided this option – ErniBrown Dec 13, 2018 at 8:09

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.

Last release listed following that link is from 2012, they seem to have newer (2018) releases at sourceforge.net/projects/pthreads4w – Zitrax Mar 9, 2019 at 18:40

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
  • Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.