Skip to main content
GameDev.net gamedev.net
🔒 Locked

[BOOST] 'clock_t' : is not a member of 'global namespace''

Started by Mybowlcut Jun 29, 2009 at 11:44 PM 26 replies 25.5k views
Original Post
Mybowlcut
Mybowlcut
Hey. I'm trying to use Boost.Filesystem:
#include "boost/filesystem.hpp"

int main()
{
    return 0;
}

But I get these errors (incidentally, the same as these):
Error	1	error C2039: 'clock_t' : is not a member of '`global namespace''	c:\program files\microsoft visual studio 8\vc\include\ctime	18
Error	2	error C2873: 'clock_t' : symbol cannot be used in a using-declaration	c:\program files\microsoft visual studio 8\vc\include\ctime	18
Error	3	error C2039: 'asctime' : is not a member of '`global namespace''	c:\program files\microsoft visual studio 8\vc\include\ctime	20
Error	4	error C2873: 'asctime' : symbol cannot be used in a using-declaration	c:\program files\microsoft visual studio 8\vc\include\ctime	20
Error	5	error C2039: 'clock' : is not a member of '`global namespace''	c:\program files\microsoft visual studio 8\vc\include\ctime	20
Error	6	error C2873: 'clock' : symbol cannot be used in a using-declaration	c:\program files\microsoft visual studio 8\vc\include\ctime	20
Error	7	error C2039: 'ctime' : is not a member of '`global namespace''	c:\program files\microsoft visual studio 8\vc\include\ctime	20
Error	8	error C2873: 'ctime' : symbol cannot be used in a using-declaration	c:\program files\microsoft visual studio 8\vc\include\ctime	20
Error	9	error C2039: 'difftime' : is not a member of '`global namespace''	c:\program files\microsoft visual studio 8\vc\include\ctime	21
Error	10	error C2873: 'difftime' : symbol cannot be used in a using-declaration	c:\program files\microsoft visual studio 8\vc\include\ctime	21
Error	11	error C2039: 'gmtime' : is not a member of '`global namespace''	c:\program files\microsoft visual studio 8\vc\include\ctime	21
Error	12	error C2873: 'gmtime' : symbol cannot be used in a using-declaration	c:\program files\microsoft visual studio 8\vc\include\ctime	21
Error	13	error C2039: 'localtime' : is not a member of '`global namespace''	c:\program files\microsoft visual studio 8\vc\include\ctime	21
Error	14	error C2873: 'localtime' : symbol cannot be used in a using-declaration	c:\program files\microsoft visual studio 8\vc\include\ctime	21
Error	15	error C2039: 'mktime' : is not a member of '`global namespace''	c:\program files\microsoft visual studio 8\vc\include\ctime	22
Error	16	error C2873: 'mktime' : symbol cannot be used in a using-declaration	c:\program files\microsoft visual studio 8\vc\include\ctime	22
Error	17	error C2039: 'strftime' : is not a member of '`global namespace''	c:\program files\microsoft visual studio 8\vc\include\ctime	22
Error	18	error C2873: 'strftime' : symbol cannot be used in a using-declaration	c:\program files\microsoft visual studio 8\vc\include\ctime	22
Error	19	error C2039: 'time' : is not a member of '`global namespace''	c:\program files\microsoft visual studio 8\vc\include\ctime	22
Error	20	error C2873: 'time' : symbol cannot be used in a using-declaration	c:\program files\microsoft visual studio 8\vc\include\ctime	22


I'm using Visual Studio and my additional include directories are set up properly... is there something I'm missing? Cheers.

fastcall22
fastcall22
I can't reproduce the problem, but it looks like your definitions aren't in both the global namespace and std as most c-header wrappers files are in Visual Studio. Try #include-ing (or ) before including

[Edited by - _fastcall on June 30, 2009 9:50:02 AM]
Mybowlcut
Mybowlcut
I tried both of those (though ctime.h couldn't be found so I used ctime instead) but no cigar. I also tried including before including "boost/filesystem.hpp" (as I recall opengl requires something like this) but that didn't do it either.

Cygon
Cygon
I had that kind of errors when I was adding Boost to a Windows CE (aka Smart Device) project. Apparently, one of the places where the windows API and libc functions were heavily trimmed was the time functions.

Any chance you accidentally created such a project?
Otherwise, which version of Visual Studio does this happen in? I've used Boost with 2005, 2005 SP1, 2008 and 2008 SP1.
If including ctime doesn't help, either your ctime is corrupted or the include guard (the "#ifndef __CTIME_SOMETHING_INCLUDED" thingy) might get set inadvertently by something else, preventing both you and Boost from obtaining the definitions contained in it.
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
Mybowlcut
Mybowlcut
Quote:
Original post by Cygon
I had that kind of errors when I was adding Boost to a Windows CE (aka Smart Device) project. Apparently, one of the places where the windows API and libc functions were heavily trimmed was the time functions.

Any chance you accidentally created such a project?
Otherwise, which version of Visual Studio does this happen in? I've used Boost with 2005, 2005 SP1, 2008 and 2008 SP1.
If including ctime doesn't help, either your ctime is corrupted or the include guard (the "#ifndef __CTIME_SOMETHING_INCLUDED" thingy) might get set inadvertently by something else, preventing both you and Boost from obtaining the definitions contained in it.
I'm pretty sure the project is a "win32 console application" project, if that's what you're asking?

I'm using 2005 Version 8.0.50727.42.

I did a search through the boost source for files containing "_CTIME_" but got no results.

:(

Codeka
Codeka
When I start getting errors like that, I tend to enable the the pre-processor output, which'll show you the "raw" file (after all #includes and #defines, etc) have been processed. That way, you can look at where things are actually being defined and so on.

The option is in your project properties, under C/C++, Preprocessor and "Generate Preprocessed File". That'll create a myfile.i in the same directory as the corresponding .cpp file(s). Then search that file for "clock_t" and see where it's being defined. Or you can search for "ctime" to find where it first includes the file and so on... I'm sure a little poking around in that file should show up whatever is going wrong.
Mybowlcut
Mybowlcut
A great suggestion from a great country! Haha. I had used that option before but had completely forgot.. I'll give it a whirl, cheers.

phresnel
phresnel
Quote:
Original post by _fastcall
I can't reproduce the problem, but it looks like your definitions aren't in both the global namespace and std as most c-header wrappers files are in Visual Studio. Try #include-ing (or ) before including


note:
Mybowlcut
Mybowlcut
Eh... I've searched for clock_t and found it. It is defined after my class called Time (which is a crappy class that I've never gotten round to scrapping), incidentally:
typedef enum TIME_FORMAT { HH_MM, MM_SS, HH_MM_SS, HH_MM_SS_MSMS };class Time{public:	typedef unsigned short ushort;	typedef unsigned int uint;	typedef unsigned long ulong;	Time(char separator = ':');	friend std::istream& operator>>(std::istream& stream, Time& time);	friend std::ostream& operator<<(std::ostream& stream, const Time& time);	friend bool operator==(const Time& lhs, const Time& rhs);	friend bool operator!=(const Time& lhs, const Time& rhs);	friend bool operator<(const Time& lhs, const Time& rhs);	friend bool operator>(const Time& lhs, const Time& rhs);	friend bool operator<=(const Time& lhs, const Time& rhs);	friend bool operator>=(const Time& lhs, const Time& rhs);	void Load_Time();	ushort Get_Milliseconds() const;	ushort Get_Seconds() const;	ushort Get_Minutes() const;	ushort Get_Hours() const;	std::string Get_Time_Formatted(TIME_FORMAT format) const;	static uint to_ms_from_s(unsigned int seconds);	static uint to_ms_from_m(unsigned int minutes);	static uint to_ms_from_h(unsigned int hours);	static uint to_s_from_ms(unsigned int milliseconds);	static uint to_s_from_m(unsigned int minutes);	static ulong to_ms_from_t(const Time& time);	static int MS_IN_S, S_IN_M, M_IN_H;private:	char separator;	ushort hours, minutes, seconds, milliseconds;};namespace std {using ::clock_t; using ::size_t;using ::time_t; using ::tm;using ::asctime; using ::clock; using ::ctime;using ::difftime; using ::gmtime; using ::localtime;using ::mktime; using ::strftime; using ::time;}
Is the the cause? The Time class is in a file called Time.h...

_moagstar_
_moagstar_
I've had this error before, it was caused by an unmatched { - it may be totally unrelated, but you might want to check that your opening braces for namespaces, classes and so also have closing braces.
Mybowlcut
Mybowlcut
Quote:
Original post by _moagstar_
I've had this error before, it was caused by an unmatched { - it may be totally unrelated, but you might want to check that your opening braces for namespaces, classes and so also have closing braces.
I'm only including boost and nothing else, and as you can see from the code sample above, I've only got one function (main) and the brackets are all ok.

I just realised.. I didn't include my Time class and I don't have the directory it is in added to "additional include directories"... that's weird. It shouldn't be included in the preprocessed output at all.

Edit: There is another file of mine being included that I never included (IO.h)...

Linker command line options are:
/OUT:"C:\Documents andSettings\Bill\My Documents\Visual Studio 2005\Projects\Test\Debug\Test.exe"/INCREMENTAL /NOLOGO /LIBPATH:"E:\Dev\boost\lib" /MANIFEST/MANIFESTFILE:"Debug\Test.exe.intermediate.manifest" /DEBUG /PDB:"c:\Documentsand Settings\Bill\My Documents\Visual Studio 2005\Projects\Test\debug\Test.pdb"/SUBSYSTEM:CONSOLE /MACHINE:X86 /ERRORREPORT:PROMPT opengl32.lib glu32.libkernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.libshell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib


C++ command line options are:
/Od /I "E:\Dev\tinyxml++" /I"E:\Dev\boost" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE"/Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /nologo /c /ZI /TP/errorReport:prompt


Should I upload the 3.5 meg, 357243 line long output file? :)

Mybowlcut
Mybowlcut
Ok, I removed some other files from the project directory which could have been causing problems. Now I have this.

_moagstar_
_moagstar_
Actually ignore me...I have had this error before, but it wasn't related to braces...I've had something very similar that was though, sorry if I've confused matters.

If I recall correctly this problem was also caused by the fact that I had a file called Time.h. The folder which this file was in was in my additional include directories, and I think this file was getting included by the instead of

I worked around the problem by changing the name of my file from Time.h to TimeUtil.h, although I think by changing the order of your additional include directories you should be able to get it to include the correct file.
_moagstar_
_moagstar_
Is it part of your project additional include directories?

EDIT : I can see from you compiler options this isn't the case. That is very strange.
Mybowlcut
Mybowlcut
I changed my Time files to something else but it still gave me the error. So, I created a whole new project with the same main file contents as the last one and it worked... here are the command line options:

Linker:
/OUT:"C:\Documents and Settings\Bill\My Documents\VisualStudio 2005\Projects\delete\Debug\delete.exe" /INCREMENTAL /NOLOGO/LIBPATH:"E:\Dev\boost\lib" /MANIFEST/MANIFESTFILE:"Debug\delete.exe.intermediate.manifest" /DEBUG/PDB:"c:\documents and settings\bill\my documents\visual studio 2005\projects\delete\debug\delete.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 /ERRORREPORT:PROMPTboost_filesystem-vc80-mt-gd-1_36.lib  kernel32.lib user32.lib gdi32.libwinspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.libuuid.lib odbc32.lib odbccp32.lib


C++:
/Od /I "E:\Dev\boost" /D "WIN32" /D "_DEBUG" /D "_CONSOLE"/D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\"/Fd"Debug\vc80.pdb" /W3 /nologo /c /Wp64 /ZI /TP /errorReport:prompt


Now it's time to spot the difference... Old project:

Linker:
/OUT:"C:\Documents and Settings\Bill\My Documents\VisualStudio 2005\Projects\Test\Debug\Test.exe" /INCREMENTAL /NOLOGO /LIBPATH:"E:\Dev\boost\lib" /MANIFEST /MANIFESTFILE:"Debug\Test.exe.intermediate.manifest"/DEBUG /PDB:"c:\Documents and Settings\Bill\My Documents\Visual Studio2005\Projects\Test\debug\Test.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86/ERRORREPORT:PROMPT boost_filesystem-vc80-mt-gd-1_36.lib  kernel32.libuser32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.libole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib


C++:
/Od /I "E:\Dev\tinyxml++" /I "E:\Dev\boost" /D "WIN32" /D"_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd/Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /nologo /c /ZI /TP /errorReport:prompt

Peter_APIIT
Peter_APIIT
What actually cause the problem and how do you solved it ?

_moagstar_
_moagstar_
Quote:
Original post by Peter_APIIT
What actually cause the problem and how do you solved it ?


The problem is that for some reason the compiler is including a different Time.h instead of the standard c library in From the compiler options given I can't see why that would be the case, unless there are some global include directories that could be causing it to find this file first before the standard header. Possible fixes are :

- Change the order of additional include directories so that the standard directories are searched first

- Change the name of the file that clashes with the standard header so that it no longer clashes

@Mybowlcut, when you created your new project did you still have the file Time.h? Or had you renamed it by then? The only difference between the compiler options that I could spot is /I "E:\Dev\tinyxml++" in the old options, and I don't think that would make a difference (unless E:\Dev\tinyxml++ contains a file called time.h - mine tinyxml version doesn't not sure about tinyxml++)
Mybowlcut
Mybowlcut
OH MY GOD.



So stupid... I didn't even see that text field down the bottom. SDL RPG Engine is some crappy old thing that I wasn't even using which just happened to have a file called Time.h (and Time.cpp if that matters).

Solved! It was what _moagstar_ had suggested: Time.h was screwing up things.

Thanks for all your help guys! I hope someone finds this if it ever happens to them... this error is the reason why the way I deal with files currently consists of just std::strings and dodgy free functions. :s

Mybowlcut
Mybowlcut
Ok... so the same program that I posted above compiles and links fine, but when I run it...



Debug it...



If I don't #include "boost/filesystem.hpp", it works fine.

Am I linking to the wrong library? I am linking to boost_filesystem-vc80-mt-gd-1_36.lib. Perhaps the boost install was dodgy? I tried a full rebuild but it still occurs.

Linker options:
/OUT:"C:\Documents and Settings\Bill\My Documents\VisualStudio 2005\Projects\Test\Debug\Test.exe" /INCREMENTAL /NOLOGO /LIBPATH:"E:\Dev\boost\lib" /MANIFEST /MANIFESTFILE:"Debug\Test.exe.intermediate.manifest"/DEBUG /PDB:"c:\Documents and Settings\Bill\My Documents\Visual Studio2005\Projects\Test\debug\Test.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86/ERRORREPORT:PROMPT boost_filesystem-vc80-mt-gd-1_36.lib  kernel32.libuser32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.libole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib


C++ options:
/Od /I "E:\Dev\boost" /D "WIN32" /D "_DEBUG" /D "_CONSOLE"/D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\"/Fd"Debug\vc80.pdb" /W3 /nologo /c /ZI /TP /errorReport:prompt


I can run it fine in the release build though, where I link to boost_graph-vc80-mt-1_36.lib.

[Edited by - Mybowlcut on July 1, 2009 7:53:57 AM]

Sc4Freak
Sc4Freak
Windows can't find the required .dll file, because you've dynamically linked to the library (since you linked to boost_filesystem-vc80-mt-gd-1_36.lib). What that means is that you need to include the .dll file (in this case, boost_filesystem-vc80-mt-gd-1_36.dll) in the same folder as your exe.

Alternatively, you statically link to the library by linking to the static version of the library (although I can't remember the name right now). Really, though, you shouldn't need to explicitly specify the library in the linker options anyway. Boost automagically links to the correct library for you (as long as you have your compiler set up to search the correct folders). By default it should link to the static version of the library.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.