Kordnak
Kordnak

Reputation: 165

Visual Studio 2017 linux can't compile if there's std::thread

So I'm trying to use Visual Studio 2017 to create a Linux project. I started out with an Empty Linux Project (as the project template), and so far everything is fine.

However, if I have

// Create a new thread for the connection to avoid clutter
std::thread newConnectionHandler(connectionHandler, iNewConnection);
newConnectionHandler.detach();

in my code, it won't compile. These are the errors that I get:

Error       E0020   identifier "__float128" is undefined
Error       In function `std::thread::thread<void(&)(int), int&>(void(&)(int), int&)':
Error       undefined reference to `pthread_create'
Error       ld returned 1 exit status

But as soon as I comment out the std::thread stuff, it compiles.

Here's what I've tried so far:

And of course I've tried multiple variations of those changes, but I always get the same error.

And my includes are:

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <thread>

EDIT: Here's also the declaration of connectionHandler:

void connectionHandler(int iConnection)

And when passing iNewConnection, the datatype is an int.

Upvotes: 4

Views: 1353

Answers (2)

arimaknp
arimaknp

Reputation: 1

Putting -pthread in Linker -> Command Line -> Additional Options worked. Even if you are using using linux project then also you need to select the project properties in visual studio.

Thank You!!

Upvotes: 0

P.W
P.W

Reputation: 26800

Put -pthread option to Linker -> Command Line -> Additional Options, it should also be the last in the link command line after all of your object and library files.

The order is important.

Upvotes: 2

Related Questions