【发布时间】:2019-04-04 10:01:47
【问题描述】:
所以我正在尝试使用 Visual Studio 2017 创建一个 Linux 项目。 我从一个空的 Linux 项目开始(作为项目模板),到目前为止一切都很好。
但是,如果我有
// Create a new thread for the connection to avoid clutter
std::thread newConnectionHandler(connectionHandler, iNewConnection);
newConnectionHandler.detach();
在我的代码中,它不会编译。这些是我得到的错误:
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
但只要我注释掉 std::thread 的东西,它就会编译。
这是我迄今为止尝试过的:
- C/C++ -> 附加选项 -> 添加
-pthread -lpthread或只是-pthread - 链接器->附加选项->添加
-pthread -lpthread或只是-pthread - 链接器 -> 库依赖项 -> 添加了
thread - 在 C++17 和 C++11 之间切换 C++ 语言标准
当然,我已经尝试了这些更改的多种变体,但我总是遇到同样的错误。
我的包括:
#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>
编辑:
这里也是connectionHandler的声明:
void connectionHandler(int iConnection)
当传递iNewConnection 时,数据类型是int。
【问题讨论】:
-
@chris 好的,完成。
-
您在摆弄链接器,但您的错误是编译器错误。我认为你的标题路径是错误的。
-
@Quentin,也许我应该保留这一半的原始评论,但第一个错误是 Intellisense,其余的是链接器输出,这意味着编译器可以正常处理。
-
@chris 哦,好吧。那我没有更好的建议了:)
-
@Kordnak:
-pthread是链接命令行中所有对象和库文件之后的最后一个吗?
标签: c++ linux multithreading visual-studio compiler-errors