std::filesystem doesn't work in DLL project - c++

I feel sorta silly asking this question, but I just cannot find a solution anywhere on the internet.
Notes:
I am using VS2019
C++17 is enabled
My problem is the following:
I want to iterate files in a directory with std::filesystem. To do so, I need to use the directory_iterator. However, when I include the filesystem library, it doesn't find the directory_iterator, so I checked the filesystem header file. It threw me a bunch of errors. I also cannot use experimental/filesystem because for some reason the path class also has errors which make the string functions unusable.
However, when I create a fresh console application, it works fine for me. No errors, directory_iterator has been found, I can iterate without issues.
Here is a small snippet of what the errors I'm being given when trying to compile:
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(917,28): warning C4003: not enough arguments for function-like macro invocation 'concat'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(921,1): error C2365: '_InIt': redefinition; previous definition was 'template parameter'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(921): message : see declaration of '_InIt'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(921,1): error C2061: syntax error: identifier '_First_InIt'

Related

Update visual studio 2017, now getting compile error C7510: 'Callback': use of dependent template name must be prefixed with 'template'

I tried compiling my project as usual after the update (15.8.0). I set showincludes to yes to figure out where the error originates, but it's all system code. Starting with stdafx.cpp, it goes through all the includes and errors out:
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\pshpack8.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\poppack.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\pshpack8.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\poppack.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\winrt\wrl\event.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\winrt\eventtoken.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\pshpack8.h
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\winrt\wrl\event.h(316): error C7510: 'Callback': use of dependent template name must be prefixed with 'template'
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\winrt\wrl\event.h(324): error C7510: 'Callback': use of dependent template name must be prefixed with 'template'
Has anyone seen this before? I googled up and down to find an answer to no avail. Short of modifying the windows sdk, not sure what to do.
Edit:
In my installed windows SDK, the error was in the file-
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\winrt\wrl\event.h
Changed line 316: return DelegateHelper::Traits::Callback(Details::Forward(callback));
to: return DelegateHelper::Traits::template Callback(Details::Forward(callback));
and line 324: return DelegateHelper::Traits::Callback(
to return DelegateHelper::Traits::template Callback(Details::Forward(callback));
Since modifying an sdk is not really a solution, Peng Du's solution by selecting non conformance in the configuration window is the way to go.
I have legacy projects and I compared the project settings side by side, finally I successfully built the new project by setting: Configuration Properties > C/C++ > Language > Conformance mode = No
When you use a dependent template name, you have to use a template keyword, for example:
foo.template bar<T>();
Till some moment MSVC was not strict about using typename and template disambiguators, but after an update the rules have changed.
The problem is in the Windows Runtime Library and some change to Visual Studio broke it. I have the same issue on this laptop which is updated to 15.8.2, my machine at home running an earlier version does not do this, since the exact same code compiles on my other machine, it's got to be a bug in VS, or a change required in WRL/event class.
EDIT: Fix to the return values above worked, bug is in the SDK, you should NOT disable /permissive- as this enables protection against Spectre and other security enhancements.

syntax error in VC xtree internal header with Qt/boost project

I'm using Boost with a Qt project.
I added these lines to my .pro file.
INCLUDEPATH += C:/local/boost_1_62_0/
LIBS += "-LC:/local/boost_1_62_0/lib64-msvc-12.0/"
I'm linking against boost, as I use a the libICP library, that includes boost/multi_array and boost/array.
When I compile, I get a lot of errors :
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree:20: error: C2143: syntax error : missing ',' before '<'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree:21: error: C2518: keyword 'typename' illegal in base class list; ignored
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree:22: error: C2518: keyword 'typename' illegal in base class list; ignored
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree:132: error: C2065: '_Iterator_base0' : undeclared identifier
I suspect xtree is used by the implementation of multi_array or array, but I don't really know where to go from here.
Ok, so I found the solution (I was working on this issue since yesterday...)
In case someone else has a similar issue, it was just a case of unbalanced } at the end of the file ICP_Registration.h, that includes libICP.

Libs ,DLLs and .h files

Im a C# guy thats why I'm lost here, this project claims to have compiled that library for Windows https://soildgeo.codeplex.com/releases/view/108738
the folder comes with Include,Lib64 and Bin64 folders. If I'm not mistaken, I only need to copy .lib files to the VC/lib folder and the folders in include to VC/include folder, so that I can start coding against these APIs, they appear in the #include<> intellisense but then they don't compile. my questions are, are my assumptions on this whole process is right ? if not what are the right steps ? and lastly, do I need to use the Dlls found in Bin64 folder at any point ?
Im using VS2013
Thanks in advance
Edit
1>------ Build started: Project: PhysBAMTest, Configuration: Debug x64 ------
1> main.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2146: syntax error : missing ';' before identifier 'attribute'
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2530: 'PhysBAM::LOG::anonymous-namespace'::cout' : references must be initialized
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2065: 'unused' : undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2143: syntax error : missing ';' before '='
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2146: syntax error : missing ';' before identifier '__attribute__'
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2530: 'PhysBAM::LOG::anonymous-namespace'::cerr' : references must be initialized
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2065: 'unused' : undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2374: 'PhysBAM::LOG::anonymous-namespace'::__attribute__' : redefinition; multiple initialization
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163) : see declaration of 'PhysBAM::LOG::anonymous-namespace'::attribute'
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2143: syntax error : missing ';' before '='
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Edit
after adding the WIN32 macro based on an answer below , I got a linker error this time
Error 1 error LNK2019: unresolved external symbol "class std::basic_ostream > & __cdecl PhysBAM::LOG::cout_Helper(void)" (?cout_Helper#LOG#PhysBAM##YAAEAV?$basic_ostream#DU?$char_traits#D#std###std##XZ) referenced in function "void __cdecl PhysBAM::LOG::anonymous namespace'::dynamic initializer for 'cout''(void)" (??__Ecout#?A0x5bbeb782#LOG#PhysBAM##YAXXZ) C:\Users...\Documents\Visual Studio 2013\Projects\PhysBAMTest\PhysBAMTest\main.obj PhysBAMTest
All those attribute, unused, __attribute__ are what some call GNU-ishms, that is, features specific to the GCC compatible compilers (GCC itself, Clang, ICC and others). But MS VC does not aim for GCC compatibility, so they just don't work.
The people that did the port to Windows managed to remove these construct by using a few precompiler tricks, I think in the file Utilities/PHYSBAM_OVERRIDE.h. But for those to work you have to define the macro WIN32. Do that in the project "C/C++ Preprocessor Settings" page, not in the code, so it will be defined for all the source files at once.
Alternatively, and this IMO would be the correct solution, patch the sources, and replace every occurrence of #ifdef WIN32 or #if defined(WIN32) with #ifdef _WIN32. The macro _WIN32 is always predefined in Win32 and Win64, but the WIN32 is not.
Well, technically you'd have to differentiate each occurence if the issue is about being a Windows system or about being a MSVC compiler (there is a GCC compiler for Windows). And then use _WIN32 for the system dependencies and _MSC_VER for the compiler ones.
And then, if you feel like it, send a patch to the Codeplex project.
UPDATE
About the linker error, that should be easy to fix: just add the necessary "*.lib" file or files to the project. You can add them to the Linker Property Pageof the project.
Additionally what you did with .lib and .h, you need to keep .dll in either in, System32 dir, or in same dir where you have exe.
Answers to this question may help you understand better.

error C2065: 'errno' : undeclared identifier in <string> in Visual Studio 2012

I had a project running in Visual Studio 2010. Now I am using Visual Studio 2012.
Now I am getting below error while building the project.
I have looked into Google and SO as well. But no where I got any solution.
c:\program files\microsoft visual studio 11.0\vc\include\string(557): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(557): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(562): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(574): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(579): error C2065: 'errno' : undeclared identifier
I have tried with including stdlib.h into the sting header file but still I am getting this same error.
Any help appreciated.
There could be several possible reasons for this problem. The
first thing you should do is to create a one line source:
#include <string>
and nothing else, and try to compile it. If this doesn't
compile, there is a problem with your installation, and you
should reinstall it. Then, just to be sure, delete everything
in your source tree except the actual sources, project files and
solution, and rebuild. There may be some old files laying
around which are somehow causing the problem. I doubt it, but
this is something you should do anyway, any time you upgrade
a compiler, or even just install a patch. (If you've got
everything under source code control, which you should, the
simplest solution is just to delete everything, and do a new,
clean checkout.)
If these measures don't solve the problem (and somehow,
I suspect they won't), there's a problem in your code base
somewhere. errno is required to be a macro by the standard;
to get the error message you cite, the macro must be undefined.
<string> includes (indirectly) a file which defines it. Given
this, the only cause I can think of is that an earlier include
file has already included a file which defines errno, and then
#undefed it. To verify this, put your #include <string> as
the very first include of your source, and see if this solves
the problem. If it does, then you have to find the file which
does the #undef, and fix it.
I had the same issue. Strangely enough, the problem was not including "using namespace std;" under the header file includes. Apparently, program would recognize "string" unless I did this, even though "char", "float", etc were recognized.

Dependencies, Namespace, and Headers

I believe have dug myself into a hole. While breaking up my single file, couple thousand line chunk of code into multiple files I appear to have grossly screwed up the structure of the program.
I'm new to C++ and its header files and namespace management so I've been learning as I go.
I guess I don't fully understand how #include, using, and namespaces interrelate and what transfers over to other files, etc.
Reading through MSDN documentation I can see bits and pieces of my problem but the solution eludes me.
As of now I have four .cpp files and headers:
1) A Main File
2) A GameData .cpp and its header that is contained in the namespace pData
3) A GameSettings .cpp and its header that is contained in the namespace pSettings
4) A GeneralScreens .cpp and its header that is contained in the namespace pScreens
Upon compile the debugger spews over 100 of error like:
>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(454): error C2447: '{' : missing function header (old-style formal list?)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(463): error C2039: 'pair' : is not a member of 'std'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(463): error C2955: 'pScreens::std::pair' : use of class template requires template argument list
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(173) : see declaration of 'pScreens::std::pair'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(33): error C2873: 'wcsrtombs' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(41): error C2039: 'wctob' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(41): error C2873: 'wctob' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2039: 'wmemchr' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2873: 'wmemchr' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2039: 'wmemcmp' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2873: 'wmemcmp' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2039: 'wmemcpy' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2873: 'wmemcpy' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(43): error C2039: 'wmemmove' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\new(93): error C2039: 'nothrow_t' : is not a member of 'std'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\new(93): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\new(93): error C2143: syntax error : missing ',' before '&'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\new(99): error C2039: 'new_handler' : is not a member of 'std'
Are these errors indicative of something?
I'm assuming something is wrong with the way I'm referencing the std library though I have no idea how to pinpoint the error because all the errors are in library files.
Most likely you're missing a semicolon on the end if a class or struct definition in a header file. The compiler then treats every identifier it sees as an instance of that class instead of what you're expecting. Then the compiler complains because it has no idea what to do with the stray {}s it sees.
Check the header that's #included just before <utility> in your implementation file; that header is most likely where the fault lies.
Side note: To avoid this problem, always #include standard headers before your own headers in a .CPP file. For example, instead of
// MyGameThing.cpp
#include "MyGameThing.hpp"
#include <utility>
#include <string>
// code
do
// MyGameThing.cpp
#include <utility>
#include <string>
#include "MyGameThing.hpp"
// code
That way you won't get compile errors like this buried in the standard headers.
The first compiler error is going to be your best clue:
c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(454): error C2447: '{' : missing function header (old-style formal list?)
I'm guessing that what's happening here is you may have a class or struct declaration with no ending semicolon. So you have something like this:
struct Foo
{
} // <--- no semicolon here will generate funky errors
But overall, pay close & special attention to the first compiler error.
As #Billy mentions in the comments below, the rules for struct and class are the same. In either case, you need the semicolon. Also, old-school C code will often typedef structs like this:
typedef struct tag_Foo
{
} Foo; // <-- still need the semicolon
Here, you still need the semicolon.
If using Visual C++, open the first cpp file and press CTRL+F7, this will compile only the cpp file, check the first error and try to correct this. When fixed go to the next cpp file if the error persists.
Billy's attempt is a decent one, but the usual response to a missing ';' is for the compiler to say so. A missing '}' on the other hand can seriously confuse standard headers included afterward because all their content is within the scope of either the namespace or class that should have been closed. Also, ';' missing is more immediately detectable while a missing '}' isn't necessarily an error so the compiler just pisses a fit at the first thing that doesn't make sense in that scope.
Furthermore, at line 454 in utility for the 2010 compiler is the opening brace for a specialization of tuple_size for std::pair. Post preprocessor that definition would look like so:
template < ... >
struct tuple_size< ::std::pair<_Ty1, _Ty2> >
If you have forgotten a '}' closing a namespace then that's not where pair<> exists anymore. Instead, since it's declared like so:
namespace std { template < ... > struct pair ... }
Whatever scope wasn't closed is now where std is being declared and struct tuple_size< ::std::pair<...> > doesn't make any sense to the parser. Since it's not a valid name it tends to pretend it's not even there and then '{' at the global scope without anything of sense before it is pretty f'n confusing.
BTW, an often unspoken benefit of making minimal examples that cause the problem is that you end up FINDING the problem trying to make it happen.