1

I heard that Nuget builds project easier without any configuration.

So, I am trying to add pthreads in my project from Nuget

(Actually I am using windows 10 x64 Visual studio 2017, C language, and my friends use linux OS)

I just search pthreads in Nuget package, click "install" button

But, my project compiles well but fatal error LNK1120 called.

Is there any more configuration after install pthreads from nuget?

TyeolRik
  • 466
  • 2
  • 25
  • Set Build log to detailed by Tools-->Options-->Projects and Solutions-->Build and Run-->set `MSBuild project build output verbosity` to `detailed` and then share the detailed error log with us. Also, what is your project type, a console or a window project? Or provide a Minimal, Reproducible Example is better for us to troubleshoot your issue. –  Apr 01 '20 at 08:44
  • @hellogod I am not using English, so, there is error ```main.obj : error LNK2019: __imp__pthread_create``` ```main.obj : error LNK2019: __imp__pthread_join``` ```fatal error LNK1120:``` – TyeolRik Apr 01 '20 at 08:47
  • can you tell us what your project type is or is it created in VS2017? –  Apr 01 '20 at 09:15
  • VS2017, new project - ConsoleApplication. There is no other things that I manually configured. (Because I usually code another languages in another IDE) – TyeolRik Apr 01 '20 at 09:19

1 Answers1

2

Is there any more configuration after install pthreads from nuget?

Using Nuget format to install pthread into C++ projects is quite simple and will not manually configure include Directories and additional Dependencies address any more.

But pthread nuget package in VS has a drawback that it does not fully inherit pthread class library. It lost a file called pthreadvc2.lib. You can try my following suggestions to configure it without any settings in project properties.

Solution

1) download pthread-w32-2-9-1-release.zip from this link.

2) unpack this file and then copy pthreadVC2.lib from the file(pthreads-w32-2-9-1-release\Pre-built.2\lib\x86 or x64) into

C:\Program Files (x86)\Microsoft Visual Studio\2017\xxxxx\VC\Tools\MSVC\xxxx.xx.xxxx\lib\x86 or x64.

Note that you should copy the related lib into the related folder, x86 pthreadVC2.lib into x86 folder, x64 pthreadVC2.lib into x64 folder.

3) then add this into your cpp file:

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

Then it will work as expected without any errors.

tpbafk
  • 501
  • 5
  • 26
LoLance
  • 25,666
  • 1
  • 39
  • 73
  • You are awesome!! I couldn't find this solution in any document. How did you know that? – TyeolRik Apr 03 '20 at 06:29
  • Thanks for your feedback and just some tests confirm it :) Besdies, If you have any other issues about nuget later, please feel free to let us know. Anyway, have a nice day! – LoLance Apr 03 '20 at 06:51
  • The zip file's link was dead. I replaced it with a working one. And the answer is solved my problem also. Thank you! – tpbafk Dec 28 '21 at 09:14