首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编译错误时,包括jemalloc.h之前的std::mutex

编译错误时,包括jemalloc.h之前的std::mutex
EN

Stack Overflow用户
提问于 2015-02-26 01:04:27
回答 4查看 4.6K关注 0票数 4

代码语言:javascript
复制
//CSocket.h
#ifndef __SERVER_CSOCKET_H__
#define __SERVER_CSOCKET_H__

#include "winsock2.h"
#include "ws2tcpip.h"

#include <thread>
#include <stdio.h>
#include <string>

(cpp只包括报头)

代码语言:javascript
复制
//CSocket.cpp
#include "CSocket.h"

在c中生成以下错误消息:\程序文件(X86)\12.0\vc\包含\比率

代码语言:javascript
复制
ratio(122): error C2065: 'INTMAX_MAX': undeclared identifier
ratio(133): See reference to the instance of the just compiled class-template "std::ratio<_Nx,_Dx>".
ratio(124): error C2065: 'INTMAX_MAX': undeclared identifier
ratio(44): error C2065: 'INTMAX_MAX': undeclared identifier
ratio(217): See reference to the instance of the just compiled class-template "std::_Safe_mult<0x01,0x01>".
ratio(36): error C2338: integer arithmetic overflow
ratio(44): See reference to the instance of the just compiled class-template "std::_Safe_multX<0x01,0x01,false>".
ratio(44): error C2039: 'value': Is not an element of 'std::_Safe_multX<0x01,0x01,false>'
ratio(44): error C2065: 'value': undeclared identifier
ratio(44): error C2057: Expected constant expression
ratio(44): error C2039: 'value': Is not an element of 'std::_Safe_multX<0x01,0x0989680,false>'
ratio(219): error C2975: "_Nx": invalid template argument for "std::ratio", expected compile-time constant expression.
ratio(116): See declaration of '_Nx'
ratio(219): error C2975: "_Dx": invalid template argument for "std::ratio", expected compile-time constant expression.
ratio(117): See declaration of '_Dx'
CSocket.cpp

包括std::.cpp中的线程而不是头中的线程解决了所有的错误,但是我不知道为什么它不能在头中工作。

代码语言:javascript
复制
//CSocket.cpp
#include "CSocket.h"
#include <thread>

我使用的唯一库是jemalloc。错误是否来自在互斥之前包含jemalloc.h,而不是线程本身?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2015-02-26 20:55:03

我必须在#include <mutex>之前#include "jemalloc.h",而不是以后。现在工作很好,但是有一些奇怪的错误。

票数 1
EN

Stack Overflow用户

发布于 2015-03-09 19:00:13

我也有同样的错误,但是包含的顺序对我没有用。我认为这与其他也使用计时和线程的内容有关,所以您可以查看它。

您在使用吗?似乎有更多的人犯了同样的错误:https://connect.microsoft.com/VisualStudio/feedback/details/800726/compiler-error

票数 1
EN

Stack Overflow用户

发布于 2016-06-29 13:46:06

我在VS2013更新3中也有同样的错误。问题似乎是INTMAX_MAX没有定义,但它被使用在ratio.h中。

我的解决办法是

代码语言:javascript
复制
#define INTMAX_MAX   INT64_MAX

在文件中的#include <ratio>之前(如果没有行,可以添加它)。

要包含的行可以在stdint.h中找到--在您的示例中,右侧可以是不同的。

PS另一种解决方案是#include <stdint.h>和定义__STDC_LIMIT_MACROS。在这种情况下,您可能会收到一些关于重复宏的警告。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28732739

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档