ctime std::命名空间冲突

ctime std:: namespace conflict

本文关键字:冲突 命名空间 ctime std      更新时间:2023-10-16

我有很多C和C++文件的项目。我尝试添加线程安全队列。在我的标题中:

#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:主要.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>

队列.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;

制作文件:

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 $@ -c $<

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

我将#include <log.h>替换为#include<libavutil/log.h>并修复了makefile中的包含路径FFMPEG_INCLUDES := -I$(FFMPEG_PATH)

谢谢@user2807083的帮助。