2016-03-14 171 views
1

我有许多C和C++文件的项目。我尝试添加线程安全队列。 在我的头:ctime std ::命名空间冲突

#include <queue> 
#include <mutex> 
#include <thread> 
#include <condition_variable> 
// Some code.. 

当我尝试编译此,其故障与此错误:

In file included from /usr/include/c++/4.9/chrono:41:0, 
      from /usr/include/c++/4.9/mutex:39, 
      from queue.hpp:4, 
      from main.cpp:24: 
/usr/include/c++/4.9/ctime:60:11: error: '::clock_t' has not been declared 
using ::clock_t; 

/usr/include/c++/4.9/condition_variable:161:23: error: 'time_t' in namespace 'std' does not name a type 
    static_cast<std::time_t>(__s.time_since_epoch().count()), 

据我了解,编译器试图找到的std :: time_ *,但为什么呢?以及如何解决它? 谢谢!

UPD:main.cpp中

#include "gpu.hpp" //Error here 

int main(int argc, char const *argv[]) { 

    return 0; 
} 

gpu.hpp

#pragma once 
#include "filter.hpp" 
#include "queue.hpp" //Error here 

#include <nvcuvid.h> 

#include <avformat.h> 

#include <vector> 

queue.hpp

#pragma once 

#include <queue> 
#include <mutex> 
#include <thread> 
#include <condition_variable> 

template<typename T> 
class CQueue 
{ 
    std::queue<T> m_queue; 
    std::mutex m_mutex; 
    std::condition_variable m_cond; 
    // ... 

第一错误消息:

In file included from queue.hpp:3:0, 
      from gpu.hpp:3, 
      from main-test.cpp:2: 
/usr/include/c++/4.9/ctime:60:11: error: '::clock_t' has not been declared 
using ::clock_t; 

Makefile:

FFMPEG_INCLUDES := -I$(FFMPEG_PATH) $(FFMPEG_PATH)/libavutil ... 

$(OBJECTS_DIRS)/app-main-test.o: src/app/main-test.cpp 
    $(CXX) $(CXXFLAGS) $(FFMPEG_INCLUDES) $(CUDA_INCLUDES) -o [email protected] -c $< 
+1

你能发布产生这个错误所需的最小代码吗?当只包含你显示的头文件而没有其他东西(比如一个空的main()函数)时它会发生吗? – Galik

+0

您是否包含[''](http://en.cppreference.com/w/cpp/header/ctime)? –

+0

删除“c”标签,因为这是无效的c。 – xaxxon

回答

2

问题出在我的Makefile中。 我已经包含了每个ffmpeg文件夹的路径。 FFMPEG_INCLUDES := -I$(FFMPEG_PATH) $(FFMPEG_PATH)/libavutil ... FFMPEG在ffmpeg/libavutil中有time.c它会导致与ctime发生冲突。

我更换#include <log.h>#include<libavutil/log.h>和固定包括makefile文件路径FFMPEG_INCLUDES := -I$(FFMPEG_PATH)

谢谢@ user2807083的帮助。