Visual Studio 2010 source annotation keywords cause name clashes - visual-studio-2010

After having converted a project from Visual Studio 2005 to Visual Studio 2010, it appears the project doesn't build anymore and spits out tons of C2059 errors like:
`error C2059: syntax error : 'type'
We're using Visual Studio 2010 Professional which doesn't provide static code analysis.
Here is the full log for the compilation of 1 C file for reference:
1>------ Build started: Project: VoHR, Configuration: Debug Win32 ------
1> AKAsynch.c
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(88): error C2059: syntax error : 'type'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(107): error C2059: syntax error : '}'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(119): error C2059: syntax error : 'type'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(139): error C2059: syntax error : '}'

I tracked down the reason of those sudden compiler errors.
In the great tradition of windows.h it appears that Microsoft introduced tokens that cause name clashes with our codebase.
In our precise case, we had:
#define Null (void*)0
Somewhere in our code, we need to use the offsetof macro and to make it available we #include <stddef.h>
I tracked down stddef.h in turns includes crtdefs.h which ends up including sal.h where our Null macro seems to clash with source code annotation in MS headers...
As a workaround, we did:
#if defined(_MSC_VER) && _MSC_VER >= 1600
#pragma push_macro("Null")
#undef Null
#endif
#include <stddef.h>
#if defined(_MSC_VER) && _MSC_VER >= 1600
#pragma pop_macro("Null")
#endif
Our use of Null as a macro is arguable, still I would have expected MS to find a way to avoid clashes with existing code bases.
Hope that helps those facing the same issue.

Related

Matlab mex command for building armaMex_demo.cpp in Armadillo in Windows

I am having troubles mex-ing armaMex_demo_cpp in Armadillo (armadillo-8.500.1) in Windows with Matlab (2018a).
So far I am trying the command:
>> mex -LC:\Users\Test\Documents\Armadillo\armadillo-8.500.1-mod_for_windows\include\armadillo -LC:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\gfortran -IC:\Users\Test\Documents\Armadillo\armadillo-8.500.1-mod_for_windows\include armaMex_demo.cpp
and get the error messages (truncated):
Building with 'Microsoft Visual C++ 2017'.
Error using mex
armaMex_demo.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\random(31): error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\random(31): error C2146: syntax error: missing ';' before
identifier 'ARMA_USE_BLAS'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\random(31): error C2143: syntax error: missing ';' before
'{'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\random(31): error C2447: '{': missing function header
(old-style formal list?)
c:\users\test\documents\armadillo\armadillo-8.500.1-mod_for_windows\include\armadillo_bits/arma_rng_cxx11.hpp(28): error C2039: 'mt19937_64': is not a
member of 'std'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\atomic(42): note: see declaration of 'std'
c:\users\test\documents\armadillo\armadillo-8.500.1-mod_for_windows\include\armadillo_bits/arma_rng_cxx11.hpp(28): error C3083: 'mt19937_64': the symbol
to the left of a '::' must be a type
c:\users\test\documents\armadillo\armadillo-8.500.1-mod_for_windows\include\armadillo_bits/arma_rng_cxx11.hpp(28): error C2039: 'result_type': is not a
member of 'std'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\atomic(42): note: see declaration of 'std'
c:\users\test\documents\armadillo\armadillo-8.500.1-mod_for_windows\include\armadillo_bits/arma_rng_cxx11.hpp(28): error C3646: 'seed_type': unknown
override specifier
Does any one have any ideas of what I may be doing wrong here?
Anybody have a working mex command for building the mex file for armaMex_demo.cpp in Windows?
Seems to have something to do with how I am including/referencing to BLAS. I used to have the line '#define ARMA_USE_BLAS' uncommented in config.hpp. By leaving it commented I, with this mex command:
mex -LC:\Users\Test\Documents\Armadillo\armadillo-8.500.1-mod_for_windows\include\armadillo -LC:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\gfortran -IC:\Users\Test\Documents\Armadillo\armadillo-8.500.1-mod_for_windows\include armaMex_demo.cpp
I only get this error:
Building with 'Microsoft Visual C++ 2017'.
Error using mex
armaMex_demo.cpp
C:\Users\Test\Documents\Armadillo\armadillo-8.500.1-mod_for_windows\mex_interface\armaMex_demo.cpp(44): error C2668: 'arma::size': ambiguous call to
overloaded function
c:\users\test\documents\armadillo\armadillo-8.500.1-mod_for_windows\include\armadillo_bits/fn_size.hpp(38): note: could be 'const
arma::SizeMat
arma::size(const T1 &)'
with
[
T1=arma::mat
]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\xutility(1654): note: or 'arma::uword
std::size(const _Container &)'
with
[
_Container=arma::mat
]
C:\Users\Test\Documents\Armadillo\armadillo-8.500.1-mod_for_windows\mex_interface\armaMex_demo.cpp(44): note: while trying to match the argument list
'(arma::mat)'
And by changing the line
if ( size(X) != size(Y) )
to
if ( X.size() != Y.size() )
in armaMex_demo.cpp
the mexing (and the mex call) works in Windows from Matlab.

Clang C2 on Visual studio 15.5 bool_constant<__is_trivially_destructible(_Ty)> error : '_Ty' does not refer to a value

I am trying to re-compile a hello world using Clang_C2 compiler on Visual studio 15.5 (latest).
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\type_traits(899,2): error : expected class name
1> { // determine whether _Ty has a trivial destructor
In file included from ..\hello_boost_exception\hello_boost_exception.cpp:11:
1>In file included from I:\modular-boost\boost/config.hpp:48:
1>In file included from I:\modular-boost\boost/config/stdlib/dinkumware.hpp:98:
1>In file included from C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\typeinfo:22:
1>In file included from C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\exception:7:
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\type_traits(898,47):
This looks as though I have some missing or incorrect library but I can't see what.
I have try various compiler versions C++14 (-std=c++1y) and library -stdlib=libc++ (should it use dinkumware version of type_traits?) but the error persists.
Suggestions most welcome.
Paul

Using std::function<void> on visual studio 2013

I am converting my project from mac os x (xcode) to windows (visual studio 2013).
But i am having problems when i try to use the std::function.
As an example i declared.
std::function<void()> processFunc;
But i get several errors:
Error 1 error C2039: 'function' : is not a member of 'std' ...github\oglengine\engine\game.h 39 1 Engine
Error 2 error C2143: syntax error : missing ';' before '<' ...github\oglengine\engine\game.h 39 1 Engine
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ...github\oglengine\engine\game.h 39 1 Engine
On XCode i needed to enable the c++11, but from what i saw on my research the VS 2013 have the C++11 enables.
My only C++ include is the iostream
Should i add another include?
I believe you need to #include <functional> in VS.

WINCE 6.0 Openssl Compilation errors

I am very new to OpenSSL. My aim is to compile OpenSSL for WINCE 6.0 OS. After spending lot of time on Google, I found a procedure to build OpenSSL for WINCE 6.0. But my attempt to build the wcecompat libraries is unsuccessful. Below is my environment
Host Platform : WINDOWS 7
Visual Studio : 2008
TargetCpu : x86
Below are the steps followed to build wcecompat:
Downloaded the source from "https://github.com/mauricek/wcecompat/tree/master" git.
Using Visual Studio Command prompt for build. Declared the env following variables:
set OSVERSION=WCE600
set TARGETCPU=x86
set PLATFORM=VC-CE
Created the make files using "perl config.pl" command.
Executed nmake command.
The build fails with compilation errors. Below are the logs:
--------------------------------------------------------------------------------------------------
args.cpp
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(235) : error C2059: syntax error : '('
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(237) : error C2059: syntax error : '('
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(239) : error C2059: syntax error : '('
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(241) : error C2059: syntax error : '('
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(243) : error C2059: syntax error : '('
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(245) : error C2059: syntax error : '('
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(247) : error C2059: syntax error : '('
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(249) : error C2059: syntax error : '('
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(251) : error C2059: syntax error : '('
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(253) : error C2059: syntax error : '('
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(255) : error C2059: syntax error : '('
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(257) : error C2059: syntax error : '('
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(258) : error C2059: syntax error : '('
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(994) : error C2556: 'const wchar_t *wcschr(const wchar_t *,wchar_t)' : overloaded function differs only by return type from 'wchar_t *wcschr(const wchar_t *,wchar_t)'
include\string.h(36) : see declaration of 'wcschr'
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(994) : error C2373: 'wcschr' : redefinition; different type modifiers
include\string.h(36) : see declaration of 'wcschr'
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(1026) : error C2556: 'const wchar_t *wcspbrk(const wchar_t *,const wchar_t *)' : overloaded function differs only by return type from 'wchar_t *wcspbrk(const wchar_t *,const wchar_t *)'
include\string.h(46) : see declaration of 'wcspbrk'
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(1026) : error C2373: 'wcspbrk' : redefinition; different type modifiers
include\string.h(46) : see declaration of 'wcspbrk'
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(1027) : error C2556: 'const wchar_t *wcsrchr(const wchar_t *,wchar_t)' : overloaded function differs only by return type from 'wchar_t *wcsrchr(const wchar_t *,wchar_t)'
include\string.h(47) : see declaration of 'wcsrchr'
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(1027) : error C2373: 'wcsrchr' : redefinition; different type modifiers
include\string.h(47) : see declaration of 'wcsrchr'
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(1029) : error C2556: 'const wchar_t *wcsstr(const wchar_t *,const wchar_t *)' : overloaded function differs only by return type from 'wchar_t *wcsstr(const wchar_t *,const wchar_t *)'
include\string.h(49) : see declaration of 'wcsstr'
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(1029) : error C2373: 'wcsstr' : redefinition; different type modifiers
include\string.h(49) : see declaration of 'wcsstr'
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(1079) : error C2264: 'wcschr' : error in function definition or declaration; function not called
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(1081) : error C2264: 'wcspbrk' : error in function definition or declaration; function not called
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(1083) : error C2264: 'wcsrchr' : error in function definition or declaration; function not called
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(1085) : error C2264: 'wcsstr' : error in function definition or declaration; function not called
include\stdio.h(62) : warning C4005: 'stdin' : macro redefinition
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(81) : see previous definition of 'stdin'
include\stdio.h(63) : warning C4005: 'stdout' : macro redefinition
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(82) : see previous definition of 'stdout'
include\stdio.h(64) : warning C4005: 'stderr' : macro redefinition
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(83) : see previous definition of 'stderr'
include\stdio.h(74) : error C2375: 'swprintf' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\swprintf.inl(85) : see declaration of 'swprintf'
include\stdio.h(75) : error C2375: 'vswprintf' : redefinition; different linkage
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\swprintf.inl(97) : see declaration of 'vswprintf'
include\stdio.h(125) : error C2733: second C linkage of overloaded function '_wfdopen' not allowed
include\stdio.h(125) : see declaration of '_wfdopen'
include\stdlib.h(48) : warning C4273: '_wputenv' : inconsistent dll linkage
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(955) : see previous definition of '_wputenv'
include\stdlib.h(90) : warning C4273: '_ultow' : inconsistent dll linkage
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(884) : see previous definition of '_ultow'
include\stdlib.h(91) : warning C4273: '_itow' : inconsistent dll linkage
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(878) : see previous definition of '_itow'
include\stdlib.h(92) : warning C4273: '_ltow' : inconsistent dll linkage
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(881) : see previous definition of '_ltow'
include\stdlib.h(95) : warning C4273: 'wcstoul' : inconsistent dll linkage
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(889) : see previous definition of 'wcstoul'
c:\workspace\wcecompat-master\src\ts_string.h(106) : warning C4996: 'wcscpy': This function or variable may be unsafe. Consider using wcscpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
include\string.h(38) : see declaration of 'wcscpy'
c:\workspace\wcecompat-master\src\ts_string.h(151) : warning C4996: 'wcscat': This function or variable may be unsafe. Consider using wcscat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
include\string.h(35) : see declaration of 'wcscat'
------------------------------------------------------------------------------------------------
Am I missing any configuration step? I got stuck for 2 weeks now. Please help me to resolve this error.
Using Visual Studio Command prompt for build...
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\wchar.h(235) : error C2059: syntax error : '('
...
It looks like you are using the standard visual studio command prompt, and not the cross-compile command prompt.
Do you have the Windows Embedded CE 6.0 Platform Builder or Mobile SDKs installed? As I understand it, Windows CE is still popular among medical equipment manufacturers (the FDA oversees medical equipment, and they don't fancy change (much like NIST and OpenSSL FIPS Validations)).
Platform Builder is licensed but the Windows Mobile SDKs are free. I don't have a link for Platform Builder because I used to install it from my MSDN discs. Here are the links to the Windows Mobile SDKs:
Windows Mobile 6.5 SDK
Windows Mobile 6.0 SDK
Windows Mobile 5.0 SDK - PocketPC
Windows Mobile 5.0 SDK - SmartPhone
(I had the links cribbed away, and they may be bad now a days. The date on the text file is from 2009/2010).
The SDK should get you the cross-compile command prompts. Unfortunately, I don't recall the exact steps. I have not worked with Windows CE in 6 or 7 years.

shellapi error when building Google Test

I downloaded Google Test.
Then i opened "gtest.sln" file.
After conversion i clicked "build" but Visual Studio 2005 gave the errors below repeatedly.
What should i do?
Thank you
3>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\shellapi.h(69) : error C2065: 'WHWND' : undeclared identifier
3>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\shellapi.h(69) : error C2146: syntax error : missing ')' before identifier 'hwnd'
3>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\shellapi.h(69) : warning C4229: anachronism used : modifiers on data are ignored
3>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\shellapi.h(69) : error C2491: 'ShellExecute' : definition of dllimport data not allowed
3>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\shellapi.h(69) : error C2059: syntax error : ')'
You probably need to change the order of include directories.
It seems to be you have PlatformSDK first in the include path; try to move it "down" so that VS include directories will be used first. It's probably that gtest is not compatible with your version of PlatformSDK.
Good luck!

Resources