1

I'm currently developing an multithreaded application for Linux in VS 2017.

As Remote Linux machine I use built-in Ubuntu bash in Windows, which was the part of anniversary update.

Compilation goes fine, the build is succesful. But right after running the program following error occurs.

  terminate called after throwing an instance of 'std::system_error'
  what():  Enable multithreading to use std::thread: Operation not permitted

I tried to fiddle with linking and compilation settings. But I just blew the entire project.

Did anybody encountered and solved this kind of problem? Thanks.

Edit: this thread was flagged as duplicate. Let me explain why I think this is different. I'm developing on Windows host with VS2017, and Im trying to achieve working debugging in VS2017. I cannot edit directly the compilation routine commands as in suggested duplicate thread.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Zeerou
  • 182
  • 11
  • Even though you are using VS2017 and Windows' Linux subsystem, your program is built and executed on Linux. As such, answer from the linked question (that is, "link with pthread library") applies to your situation; you just need to figure out how to make VS do that. – Andrey Turkin Apr 13 '17 at 02:48
  • That's why I asked here, I'm aware of that. I followed most of the tutorials how to tell VS to use pthread in compilation, but unsuccessfully. – Zeerou Apr 13 '17 at 05:45
  • 3
    Fair enough, I guess. I'm assuming platform toolset is "Remote_GCC_1_0"; all you need to do is add "-pthread" to compile and link command lines. VS configuration maps most g++ options to specific configuration values, but not this one. Go to project's configuration, "C/C++ -> All Options", add "-pthread" to "Additional Options" configuration value. Go to "Linker -> All Options" and do the same. – Andrey Turkin Apr 13 '17 at 06:25
  • Finally solved. Thanks. Basically I followed what you said, and I had to add Additional Options for both file settings and project settings. – Zeerou Apr 13 '17 at 06:52
  • You shouldn't have to modify file settings - they are supposed to be inherited from project level. Something went wrong there but that's a separate issue from the thread issue – Andrey Turkin Apr 13 '17 at 11:45
  • @AndreyTurkin Thanks Andrey. I had the same problem as I initially defined the `-pthread` option in C/C++ only, not in Linker. So your answer helped. You should turn it to a plain answer, by the way. – Shlublu Jul 18 '17 at 07:30

1 Answers1

2

I know that @Andrey Turkin has already given the answer in the comments. I want to add it as Answer here as not all will read the comments. I have been searching for the same for 2 days now and @Andrey Turkin helped me solve this. Please follow his comment to clear this problem.

Assuming platform toolset is "Remote_GCC_1_0"; all you need to do is add "-pthread" to compile and link command lines. VS configuration maps most g++ options to specific configuration values, but not this one. Go to project's configuration, "C/C++ -> All Options", add "-pthread" to "Additional Options" configuration value. Go to "Linker -> All Options" and do the same.

NotSoBrainy
  • 63
  • 10