1

I have project with many C and C++ files. I try to add thread-safe queue. In my header:

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

When I try to compile this, its fault with this errors:

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()),

As I understand it, compiler try to find std::time_*, but why? And how fix it? Thanks!

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;
  // ...

First error message:

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 $@ -c $<
fandyushin
  • 2,350
  • 2
  • 20
  • 32
  • 1
    Can you post the minimum code required to produce this error? Does it happen when only including the header files you showed and nothing else (like an empty main() function)? – Galik Mar 14 '16 at 08:31
  • Have you included [``](http://en.cppreference.com/w/cpp/header/ctime)? – Some programmer dude Mar 14 '16 at 08:31
  • removed "c" tag, as this is not valid c. – xaxxon Mar 14 '16 at 08:36
  • @Galik No, I can't post here main.cpp, cuz its huge. Joachim Pileborg, I tried but it not helped. I have small example with same queue code, and its working fine. I think its dependence C and C++ code? but I don't know exactly. – fandyushin Mar 14 '16 at 08:38
  • 1
    @fandyushin The idea is to delete chunks of your code to isolate that part causing the error and post only that. Doesn't the error message tell you what line number the error is on? – Galik Mar 14 '16 at 08:40
  • @xaxxon I have C and C++ files in this project, I think the problem is in conflict some C and C++ includes. Small example with this queue working fine. – fandyushin Mar 14 '16 at 08:40
  • 2
    Please try to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve) and show us. – Some programmer dude Mar 14 '16 at 08:41
  • @JoachimPileborg unfortunately minimal example working fine – fandyushin Mar 14 '16 at 08:42
  • @Galik the error is on `#include` line. I think may be someone faced with same problem, but people without reading Q downvoting :) – fandyushin Mar 14 '16 at 08:47
  • @fandyushin The error message says something about `main.cpp` line `24`. Can you post what's on line `24` of `main.cpp`? Or maybe the first 25 lines of code? – Galik Mar 14 '16 at 08:51
  • @Galik , done, I write small sample – fandyushin Mar 14 '16 at 09:02
  • Remove `using namespace std; ` from **all** your header files (and prefereably all your other code too). See if that fixes it. https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice – Galik Mar 14 '16 at 09:08
  • @Galik sorry, I forgot to remove it, it was test, but anyway it doesn't help. – fandyushin Mar 14 '16 at 09:10
  • Do you really have a header file called `#include "queue.hp"`? Should that be `#include "queue.hpp"`? You should add only one thing at a time when you code and make sure that part works before continuing. – Galik Mar 14 '16 at 09:11
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/106207/discussion-between-fandyushin-and-galik). – fandyushin Mar 14 '16 at 09:14
  • can you show the lines around where you include condition_variable? I am wondering if you've pulled ctime into another namespace or something? – Richard Hodges Mar 14 '16 at 09:16

1 Answers1

4

The problem was in my Makefile. I has include path to each ffmpeg folder. FFMPEG_INCLUDES := -I$(FFMPEG_PATH) $(FFMPEG_PATH)/libavutil ... FFMPEG have time.c in ffmpeg/libavutil It causes conflict with ctime.

I replaced #include <log.h> to #include<libavutil/log.h> and fixed include path in makefile FFMPEG_INCLUDES := -I$(FFMPEG_PATH)

Thank you @user2807083 for help.

fandyushin
  • 2,350
  • 2
  • 20
  • 32