Successfully compiled the code containing <pthread.h> under VS2017:

  • VS2017 configuration uses #<pthread.h> https://blog.csdn.net/cry1994/article/details/79115394 (The original SystemWow64 stores 32 files.)
  • Errors encountered after configuration and solutions:
    • Error in pthread.h: C2011 "timespec": " struct " type redefinition   
    • Workaround:    Add define HAVE_STRUCT_TIMESPEC below #if !defined( PTHREAD_H )   #define PTHREAD_H   This will tell pthreads, the Win32 header, that you already have an appropriate timespec and will make your code compile fine.                                                       
    • obj error: unresolved external symbol __imp__pthread_create, which is referenced in function _main   
    • Solution: #include <iostream>   #include <pthread.h>   using namespace std;   in the .cpp file , add #pragma comment(lib, "pthreadVC2.lib") // indicates linking the library pthreadVC2.lib. The effect is the same as writing the link into Ws2_32.lib in the project settings, but the program written in this method does not need to set the project settings when others use your code.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325884547&siteId=291194637