ctime Error when including boost::filesystem - c++

I am working on small project. The essential part is, that a video should be captured, saved and moved to another folder.
For the video part I am using FFmpeg this works without any problems. To safe information I am using tinyXML2. For copying and moving of the video files I like to use boost.
At the moment I am working on windows, and I am using CMake.
The problem is, that in the moment I include the "boost/filesystem" the compiler starts failing. After the use of google and analyzing the error messages I think that there is a problem with headers <ctime> or <time>. The file that is using <ctime> is xmltest that is passed by tinyxml2.
But to be honest I am very much clueless how and why this happens.
I already tried to switch the order of the includes as mentioned here.
I tried to exclude the file that uses ctime, but this is not possible.
I tried to work around the problem, so I don't have to use Boost, but this is hard due to the platform independency.
The log file:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(19): error C2039: 'clock_t': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(19): error C2873: 'clock_t': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(23): error C2039: 'asctime': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(23): error C2873: 'asctime': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(24): error C2039: 'clock': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(24): error C2873: 'clock': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(25): error C2039: 'ctime': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(25): error C2873: 'ctime': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(26): error C2039: 'difftime': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(26): error C2873: 'difftime': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(27): error C2039: 'gmtime': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(27): error C2873: 'gmtime': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(28): error C2039: 'localtime': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(28): error C2873: 'localtime': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(29): error C2039: 'mktime': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(29): error C2873: 'mktime': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(30): error C2039: 'strftime': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(30): error C2873: 'strftime': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(31): error C2039: 'time': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(31): error C2873: 'time': symbol cannot be used in a using-declaration
The way I include Boost & tinyxml:
find_package(TinyXML2)
find_package(Boost COMPONENTS filesystem system REQUIRED)
...
add_executable(programm ${project_sources}
${project_headers}
${TINYXML_INC})
target_link_libraries(programm PUBLIC
Boost::filesystem
Boost::system
${TinyXML2_LIBRARIES})
target_include_directories(programm PRIVATE
${Boost_INCLUDE_DIRS}
${Boost_LIBRARY_DIRS}
${TinyXML2_INCLUDE_DIR})
target_link_directories(programm PUBLIC
${Boost_INCLUDE_DIRS}
${Boost_LIBRARY_DIRS}
${TinyXML2_INCLUDE_DIR})
The include of Boost in Util.h:
#include <string>
#include <boost/filesystem.hpp>
namespace util {
bool existens_file(std::string* path);
int existens_directory(std::string* path);
bool create_directory(std::string* path);
}
Part in xmltest where <ctime> is used:
#include "tinyxml2.h"
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <ctime>
...
XMLDocument* doc = new XMLDocument();
clock_t startTime = clock();
doc->LoadFile( argv[1] );
clock_t loadTime = clock();
int errorID = doc->ErrorID();
delete doc; doc = 0;
clock_t deleteTime = clock();
EDIT
After some Testing I tried to use <ctime> in diffrent files without the include of boost. In this case I also receive the same problems as mentioned above.

So I fixed the issue, in the ffmpeg-library is file that is called time.h or Time.h.
The misstake was that accidentally linked the directory that contained this file.
I don't know why but with the include of boost::filesystem this was triggered and the time-file of ffmpeg was used.
I resolved this problem, through removing the linked directory of ffmpeg.

Related

Adding AdditionalIncludeDirectories makes project unable to import from standard library

I have a project in Visual Studio that is set up with the following architecture:
src
main.cpp
math.cpp
include
math.h
math.h contains function prototypes for the functions found in math.cpp. When using #include "math.h" after adding include\ to the project's C/C++ Additional Include Directories, I find the compiler is not able to find the standard library. I get several errors like this:
...
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\cmath(261,18): error C2039: 'sinhf': is not a member of '`global namespace''
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\cmath(261,23): error C3861: 'sinhf': identifier not found
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\cmath(265,18): error C2039: 'sqrtf': is not a member of '`global namespace''
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\cmath(265,23): fatal error C1003: error count exceeds 100; stopping compilation
Of course, I can successfully include include\ by using #include "..\include\math.h" but I know there must be a way to tell Visual Studio to look in \include for files to include. Any ideas on what I am doing incorrectly?

C2039 and C2873 when including `<cctype>` from the STL

I'm trying to compile a project with msvc 2019 compilers that I know has been compiled before. In fact, I'm actually updating the build system for it. I've come across a strange problem with sources from the standard template library. Basically the project includes <cctype> which pulls in the following snippet:
_STD_BEGIN
using _CSTD isalnum;
using _CSTD isalpha;
using _CSTD iscntrl;
using _CSTD isdigit;
using _CSTD isgraph;
using _CSTD islower;
using _CSTD isprint;
using _CSTD ispunct;
using _CSTD isspace;
using _CSTD isupper;
using _CSTD isxdigit;
using _CSTD tolower;
using _CSTD toupper;
using _CSTD isblank;
_STD_END
But these declarations all error with the following when I compile my project.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(38): error C2039: 'isalnum': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(38): error C2873: 'isalnum': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(39): error C2039: 'isalpha': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(39): error C2873: 'isalpha': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(40): error C2039: 'iscntrl': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(40): error C2873: 'iscntrl': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(41): error C2039: 'isdigit': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(41): error C2873: 'isdigit': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(42): error C2039: 'isgraph': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(42): error C2873: 'isgraph': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(43): error C2039: 'islower': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(43): error C2873: 'islower': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(44): error C2039: 'isprint': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(44): error C2873: 'isprint': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(45): error C2039: 'ispunct': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(45): error C2873: 'ispunct': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(46): error C2039: 'isspace': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(46): error C2873: 'isspace': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(47): error C2039: 'isupper': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(47): error C2873: 'isupper': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(48): error C2039: 'isxdigit': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(48): error C2873: 'isxdigit': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(49): error C2039: 'tolower': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(49): error C2873: 'tolower': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(50): error C2039: 'toupper': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(50): error C2873: 'toupper': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(52): error C2039: 'isblank': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(52): error C2873: 'isblank': symbol cannot be used in a using-declaration
The result is the same with both c++11 and c++14. I attempted to make a minimal working example but could not because my toy project that includes and uses <cctype> compiles without problems. Therefore it must be a problem with my project settings somewhere.
I know this is going to be a tough one, but does anybody have any thoughts on what might be happening here?
I had the same error on the macOS platform; the solution for me was to #include <_ctype.h> - this header defines the is* functions.

error C2039: 'fabs': is not a member of '`global namespace''

My project compiled well, even with full rebuild, then I modified a single parameter in a dialog resource and now it doesn't compile even changing back the parameter, I have many errors, beginning with that:
1>C:\Program Files\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\cstdlib(24,18): error C2039: 'fabs': is not a member of '`global namespace''
1>C:\Program Files\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\cstdlib(24,22): error C3861: 'fabs': identifier not found
1>C:\Program Files\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\cstdlib(28,18): error C2039: 'fabsf': is not a member of '`global namespace''
1>C:\Program Files\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\cstdlib(28,23): error C3861: 'fabsf': identifier not found
1>C:\Program Files\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\cstdlib(32,18): error C2039: 'fabsl': is not a member of '`global namespace''
1>C:\Program Files\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\cstdlib(32,23): error C3861: 'fabsl': identifier not found
There's also in cmath:
1>C:\Program Files\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\cmath(31,18): error C2039: 'acosf': is not a member of '`global namespace''
1>C:\Program Files\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\cmath(31,23): error C3861: 'acosf': identifier not found
1>C:\Program Files\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\cmath(35,18): error C2039: 'acoshf': is not a member of '`global namespace''
1>C:\Program Files\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\cmath(35,24): error C3861: 'acoshf': identifier not found
As it is in side Microsoft files I don't see what I can do.
EDIT: If I select "go to definition" in cmath, it seems that all these function are not declared because of _CRT_FUNCTIONS_REQUIRED not beeing defined, maybe it can help.
As the problem ocured after I modified the resource and I found that fabs was not declared because of _CRT_FUNCTIONS_REQUIRED not set to 1, I checked my resource.h file (comming from the original project) and saw that many definition lines where set and one containing #define _CRT_FUNCTIONS_REQUIRED 0.
I commented out all the lines and uncommented the missing definition, and I was able to compile.

Visual Studio All c++ functions are not members of global namespace

I recently installed Visual studio as I'm working to pick up c++ more. However in c++, even running something as simple as a hello world code yields me a huge number of errors such as
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(24,18): error C2039: 'fabs': is not a member of 'global namespace'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(24,22): error C3861: 'fabs': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(28,18): error C2039: 'fabsf': is not a member of 'global namespace'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(28,23): error C3861: 'fabsf': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(32,18): error C2039: 'fabsl': is not a member of 'global namespace'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(32,23): error C3861: 'fabsl': identifier not found
The error seems to be either an issue with my VS setup or my C++ Distribution. Is this a common issue? Has anyone else seen this before?
Here is the code
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
return 0;
}

Access global namespace from proxy header

I have a namespace called "access" in project. This is actually used in many places inside the project. Currently I am writing unit test case for this project. I my unit test, the io.h file getting included from the UT frame work. This io file contains c function called "access". So when I tried to include both the io file and one of my project file, I got the re-definition error for "access".
So I tried to use the proxy header for solving the above problem. For proxy header I included the frame work header file in a namespace to avoid re-definition error.
But that frame work file accessing some global namespaces. So I am getting more issues with that. Is there any way to solve the issue without renaming the namespace.
Here is my sample code.
#pragma once
#include "io.h"
#include <iostream>
class Class01
{
public:
Class01(void);
~Class01(void);
void function() {
std::cout<< " Write something";}
};
#pragma once
namespace access
{
class Class02
{
public:
Class02(void);
~Class02(void);
};
}
proxy header
#pragma once
namespace sample
{
#include "Class01.h"
};
#include "Class02.h"
// NamespaceRedef.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
//#include "Class02.h"
//#include "Class01.h"
#include "proxyHeader.h"
using namespace sample;
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
When I compile the code, I got the following error...
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2039: 'acosf' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2873: 'acosf' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2039: 'asinf' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2873: 'asinf' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2039: 'atanf' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2873: 'atanf' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2039: 'atan2f' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2873: 'atan2f' : symbol cannot be used in a using-declaration crosoft visual studio 10.0\vc\include\cmath(20): error C2873: 'atanf' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2039: 'atan2f' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2873: 'atan2f' : symbol cannot be used in a using-declaration