I have a project in CodeBlocks (MinGW32) which is setup like this :

Foo/src/somefile1.cpp
Foo/src/somefile2.cpp
Foo/src/somefile1.h
...

Headers are included that way :

#include "somefile1.h"

In order to be able to compile I have added the following directory in "Project options" > "Search directories" (as a relative path) :

src

After adding that folder, the project compiles. However, if I include a standard header like <ctime> the following errors appears in ctime header file :

'::clock_t' has not been declared
'::time_t' has not been declared
...

and so on for all lines inside the std namespace brackets of ctime. If I remove the src folder from search directories, I can compile again.

I have reduced the code to the bare minimum, removed all files except main.cpp, but the problem is still there :

#include <ctime> //errors if "src" folder added in search folders

int main(int argc, char **argv) {
    time(NULL); //does not compile
    return(0);
}
2

There are 2 answers

1
tigrou On BEST ANSWER

I found the problem :

In the project I'm trying to compile there is a file named "time.h".

It has same name as standard library time.h file. Because of this, inside ctime file, the time.h of the project is included (which doesn't contains clock_t and other definitions) and thus ctime cannot be compiled.

As solution, I have simply renamed time.h of the project to a not reserved name.

3
AudioBubble On

The <ctime> header puts the names into the std namespace, so you want:

std::time(NULL);

You probably have a using namespace std; in one of your own header files - don't do that.

Also, you typically want to include your own headers like this:

#include "somefile1.h"