Latest Visual Studio 2019 v 16.10.0 and _DEPRECATE_TR1_NAMESPACE - visual-c++

I am programming with /std:c++latest in VS2019 v16.10.0. Everything compiled fine with previous version of VS2019. Now I get many errors in header related to _DEPRECATE_TR1_NAMESPACE.
How can I compile around this deprecation?
An example of an error follows:
error C2146: syntax error: missing ';' before identifier 'subtract_with_carry_01'
where the code referenced is:
template <class _Ty, size_t _Wx, size_t _Sx, size_t _Rx>
class _DEPRECATE_TR1_NAMESPACE subtract_with_carry_01
: public _Swc_base<_Ty, _Sx, _Rx, _Swc_01_traits<_Ty, _Wx, _Rx>> { // subtract_with_carry_01 generator

The workaround I found was to
#define _HAS_TR1_NAMESPACE 0
before all header files.
Or to add _HAS_TR1_NAMESPACE=0; in the preprocessor definitions...
This allows me to use latest C++ language!!

Related

<iostream> and #define __STDC_WANT_SECURE_LIB__ 0 results in error C2039: 'sprintf_s'

When building this very simple test program
#include <iostream>
int main() {
std::cout << "x";
}
with visual studio 2019 and /Wall I'm getting a
warning C4668: '__STDC_WANT_SECURE_LIB__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
Trying to
#define __STDC_WANT_SECURE_LIB__ 0
before including iostream results in
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xlocnum(1388,69): error C2039: 'sprintf_s': is not a member of '`global namespace''
at least for my VS. Godbolt doesn't complain.
#define __STDC_WANT_SECURE_LIB__ 1
is fine and doesn't let the compiler complain about sprintf_s which one would expect.
Microsoft doesn't show me any results when searching for it.. SO does here but overall i can't find many resources on if and how to use that define.
Is there a way to disable the secure extensions and include <iostream> ? Am i using the wrong define or approach for this?

gmock and gtest linker errors in vc++ 2015 community edition

I'm tyring to configure gmock/gtest in vc++ 2015, namely
downloaded gmock and gtest
added E:\googlemock\googletest\include and E:\googlemock\googlemock\include in VC++ include directories.
compiled gmock.sln and added E:\googlemock\googlemock\msvc\2015\Debug to the Library directories.
added gmock.lib to Linker -> Input Additional dependencies.
And on building I'm getting a bunch of linker errors as below.
As i don't have any clue about the gmock/ gtest code. How shall I reason / proceed further in fixing these problems ?
code:
int main(int argc, char **argv)
{
testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}
Error **LNK2038** mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in ArrayOperations.obj ConsoleApplication3 E:\projects\cpp\ConsoleApplication3\ConsoleApplication3\gmock.lib(gtest-all.obj)
Error **LNK2005** "public: bool __thiscall std::ios_base::good(void)const " (?good#ios_base#std##QBE_NXZ) already defined in gmock.lib(gtest-all.obj) ConsoleApplication3 E:\projects\cpp\ConsoleApplication3\ConsoleApplication3\msvcprtd.lib(MSVCP140D.dll) 1
and more bunch of errors on the same LNK category*
Finally I could solve the problem by adding in properties -> c++ code generation
Run time Library to Multi-threaded Debug (/MTd) as from the post.
Mismatch Detected for 'RuntimeLibrary'

Issue in convert project from vc6 to vc9

I have a project that was build in vc6,Now I have to convert it into vc9.
In the code there is line
CMapStringToOb cLogPathMap;
ofstream tlogFile;
But when I build the project the following error occur.
error C2146: syntax error : missing ';' before identifier 'tlogFile'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
When I go to definition of ofstream the file iosfwd is opened where ofstream defined as
typedef basic_ofstream<char, char_traits<char> > ofstream;
The following microsoft suggests to include fstream:
http://msdn.microsoft.com/en-us/library/e9cabcax%28v=vs.90%29.aspx
So put the following line in your header includes for that c++ file:
#include <fstream>

WDK (Windows Driver Kit) and VC++ headers problem

I'm trying to read from an USB HID device, I know how to do it in C# using DLLImport hid.dll, but I want to do it from C++, this way I don't have to declare all the structures, etc, and just include the headers files.
So I downloaded the WDK and then when including the headers files and linking the libraries I'm getting a lot of errors:
#include <windows.h>
extern "C" {
#include <hidsdi.h>
}
int main(){
}
Errors (6 out of 163):
Error 1 error C2065: 'PASSIVE_LEVEL' : undeclared identifier c:\winddk\7600.16385.1\inc\api\hidpi.h 302 driver
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\winddk\7600.16385.1\inc\api\hidpi.h 303 driver
Error 3 error C2146: syntax error : missing ';' before identifier 'NTSTATUS' c:\winddk\7600.16385.1\inc\api\hidpi.h 303 driver
Error 4 error C2143: syntax error : missing ';' before '__stdcall' c:\winddk\7600.16385.1\inc\api\hidpi.h 303 driver
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\winddk\7600.16385.1\inc\api\hidpi.h 303 driver
Error 6 error C2377: 'NTSTATUS' : redefinition; typedef cannot be overloaded with any other symbol c:\winddk\7600.16385.1\inc\api\hidpi.h 303 driver
OK so I read somewhere that I have to upgrade the Windows SDK too, I had the Microsoft Windows SDK v6.0A, I downloaded and installed the windows SDK v7.0. But then looks like I have two SDK now? How I properly do the SDK upgrade in visual studio?
I very much appreciate your help,
Thanks,
Carlos
I found a solution, don't know why this is working, but it is!:
In Visual Studio go to:
Tools->Options->Projects->VC++ Directories and then Show directories for: include files.
Add this folders:
C:\WinDDK\7600.16385.1\inc\ddk and C:\WinDDK\7600.16385.1\inc\api
Now here is the trick that solved the problem for me and I don't know why, because seems odd but here it is:
C:\WinDDK\7600.16385.1\inc\ddk -> This directory have to be the first directory in the list!
C:\WinDDK\7600.16385.1\inc\api -> This directory have to be ABOVE "$(WindowsSdkDir)\include" BUT BELOW "$(VCInstallDir)include"
Example:
C:\WinDDK\7600.16385.1\inc\ddk
$(VCInstallDir)include
$(VCInstallDir)atlmfc\include
C:\WinDDK\7600.16385.1\inc\api
$(WindowsSdkDir)\include
$(FrameworkSDKDir)include
Carlos

Problems during Migration from VS 2003 to VS 2008

I have converted one of my Visual studio 2003 projects into VS2008 and when trying to build the project in VS2008 I get the below mentioned error.
In oledb.h, I have
typedef LONG DBROWCOUNT;
and in sybdb.h, I have
#define DBROWCOUNT 16
When I compile, I get the following errors:
c:\program files\microsoft sdks\windows\v6.0a\include\oledb.h(633) : error C2143: syntax error : missing ';' before 'constant'
c:\program files\microsoft sdks\windows\v6.0a\include\oledb.h(633) : error C2059: syntax error : 'constant'
c:\program files\microsoft sdks\windows\v6.0a\include\oledb.h(3005) : error C2059: syntax error : 'constant'
If I comment the //#define DBROWCOUNT 16, then these errors are solved,but I am not supposed to make changes in code, so please help me to come over this error,thanks in advance.
The problem seems to be that DBROWCOUNT is defined as 16 so it is replaced by preprocessor which results in the line
typedef LONG DBROWCOUNT;
being converted to
typedef LONG 16;
after preprocessing, which is clearly an error. But without looking at the code I can't say why this wasn't happening in vs2003.
While I can't speak to how this was not a problem with VC 2003, the main issues here is that you've defined DBROWCOUNT as both a type and a macro constant (which isn't allowed, as you know.) You're going to have to make a change somewhere, or else you won't be able to fix the compiler error. If oledb.h is a system header, then the change will have to be to your constant:
#define DBROWCOUNT 16
Can you change that define macro to read something like:
#define dbRowCount_k 16
And then replace DBROWCOUNT with dbRowCount_k in the places in your code where you are using that value as an integer (as opposed to a type)?

Resources