Visual C++ compiler, errors compiling stdlib.h - c++

I am trying to compile a file which requires functions included from cmath. I do not believe my code itself to be at fault for causing this error, I suspect the configuration (it persists even with all of the non-include code commented), but have no idea what is going wrong. I am compiling on a Windows host, 64 bit. Other than adding the masm build configuration, I don't believe I've changed any compile settings to non-default, and the problem persists after disabling masm, and by setting the target configuration to 32 bit. Here is my generated output:
1>...\VStudio\VC\include\stdlib.h(467): error C2062: type 'long' unexpected
1>...\VStudio\VC\include\stdlib.h(467): error C2062: type 'long' unexpected
1>...\VStudio\VC\include\stdlib.h(467): error C2059: syntax error : ')'
1>...\VStudio\VC\include\stdlib.h(468): error C2143: syntax error : missing ';' before '{'
1>...\VStudio\VC\include\stdlib.h(468): error C2447: '{' : missing function header (old-style formal list?)
1>...\VStudio\VC\include\stdlib.h(471): error C2062: type '__int64' unexpected
1>...\VStudio\VC\include\stdlib.h(471): error C2062: type '__int64' unexpected
1>...\VStudio\VC\include\stdlib.h(471): error C2059: syntax error : ')'
1>...\VStudio\VC\include\stdlib.h(472): error C2143: syntax error : missing ';' before '{'
1>...\VStudio\VC\include\stdlib.h(472): error C2447: '{' : missing function header (old-style formal list?)
Any help would be greatly appreciated.
Edit:
I have found the troublesome line. Contrary to my expectation, the error does occur in the code, and is the fault of a line inherited from a previous version:
#define abs(a) ((a)<0? -(a):(a))
is responsible for my problems.

Next time, #include system headers before any of your own code. That way your macros can't mess with the system headers and lead you astray.

Related

Installing OpenCV in C++ Visual Studio: How can I fix these linker errors that occur although I followed the installation tutorial?

I have tried downloading the C++ OpenCV Library to Visual Studio 2019.
When trying to compile my code, I am getting these errors:
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(40,9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(40,19): error C2059: syntax error: 'constant'
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(42,1): error C2143: syntax error: missing ';' before '{'
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(42,1): error C2447: '{': missing function header (old-style formal list?)
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(68,62): error C2039: 'has_parenthesis_operator': is not a member of 'cv::sfinae'
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(39): message : see declaration of 'cv::sfinae'
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(68,1): error C2065: 'has_parenthesis_operator': undeclared identifier
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(68,1): error C2977: 'std::enable_if': too many template arguments
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xtr1common(46): message : see declaration of 'std::enable_if'
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(68,117): error C2955: 'std::enable_if': use of class template requires template argument list
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xtr1common(46): message : see declaration of 'std::enable_if'
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(68,131): error C2988: unrecognizable template declaration/definition
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(68,131): error C2059: syntax error: '>'
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(69,11): error C2988: unrecognizable template declaration/definition
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(69,11): error C2059: syntax error: 'public'
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(69,1): error C2143: syntax error: missing ';' before '{'
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(69,1): error C2447: '{': missing function header (old-style formal list?)
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(80,26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(140): message : see reference to class template instantiation 'cv::Ptr<T>' being compiled
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(80,35): error C2059: syntax error: 'constant'
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(80,26): error C2334: unexpected token(s) preceding ':'; skipping apparent function body
1>C:\opencv-4.5.4\opencv\build\include\opencv2\core\cvstd_wrapper.hpp(140,1): fatal error C1903: unable to recover from previous error(s); stopping compilation
I suspect it is a linker errors, so I went ahead and made sure I have included all the dependencies and libraries, and I have done as follows, I included the opencv libraries and the library directories and added the additional dependencies:
yet I am still getting the same errors. Does anyone know how I can get rid of them?
Thank you for your help!
Link to the images: https://imgur.com/a/M1UV7yL

Having issues with linking to boost library (C++ in Visual Studio 2013)

I have been banging my head on this for a few days now. I tried downloading and compiling the latest boost 1.67.0, to include
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/process.hpp>
But I got the errors seen below when trying to compile (one thing I noticed about it is that the path has slashes going the wrong way in the error log and Im not sure how to fix that?
I tried compiling with standard cmd and also Visual Studio 2013 prompt (same result).
I then tried grabbing the precompiled version from boost site
boost_1_67_0-msvc-12.0-32.exe
And am still getting the same problem. The #include text is not underlined in the editor. And I have additional include directories pointing to:
C:\VisualStudioLibraries\boost_1_67_0
and Linker Additional Library Directories to
C:\VisualStudioLibraries\boost_1_67_0\stage\lib
Does anyone know how to resolve this? If I comment out the #include lines for boost the code compiles without any issues and program runs. My code doesnt use anything from boost yet, so the only boost related stuff in there are the 3 #include lines.
Errors are:
1> MyForm.cpp
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(65): error C3646: 'noexcept' : unknown override specifier
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(72): error C2660: 'boost::process::process_error::process_error' : function does not take 2 arguments
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(77): error C2660: 'boost::process::process_error::process_error' : function does not take 2 arguments
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(82): error C2440: '' : cannot convert from 'std::error_code' to 'boost::process::process_error'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(88): error C2440: '' : cannot convert from 'const std::error_code' to 'boost::process::process_error'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(94): error C2660: 'boost::process::process_error::process_error' : function does not take 2 arguments
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(97): error C2146: syntax error : missing ';' before identifier 'Char'
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(97): error C2146: syntax error : missing ';' before identifier 'null_char'
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(97): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(98): error C2144: syntax error : 'char' should be preceded by ';'
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(98): error C2143: syntax error : missing ';' before '<'
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(99): error C2143: syntax error : missing ';' before '{'
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(99): error C2447: '{' : missing function header (old-style formal list?)
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(101): error C2146: syntax error : missing ';' before identifier 'Char'
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(101): error C2146: syntax error : missing ';' before identifier 'equal_sign'
1>C:\VisualStudioLibraries\boost_1_67_0\boost/process/detail/config.hpp(101): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Thank you all very much.
Well, Im sure this is not the answer most will want to hear, but after trying for over a week to get it to work the only thing that ended up working was to move on to Visual Studio 2017. Everything linked and compiled fine there. Perhaps there is an issue with my VS2013 install (but everything else works flawlessly on it).

Winbase.h doesn't support in creating DLL file

I would like to create a project use to call c++ method using c#. So, I need to create a dll file for all of my c++ function. But when i get an error in y sqlite source code such as "AreFileApisASNSI undeclared identifier". So, i import winbase.h which is part of the mingw-w64 runtime package to my visual studio 2012 express DLL project. After import the file, I get many errors such as below:-
error c4430: missing type specifier - int assumed. Note: C++ does not support default - int
error C2143: syntax error : missing ';' before '_stdcall'
error c1003 error count exceeds 100; stopping compilation
error c2061: syntax error: identifier ' WINBOOL'
error c2086: 'int_CRT_INLINE' : redefinition
error c2143: syntax error: missing ';' before ''
error C2146: syntax error : missing ';' before identifier 'LONGLONG'
error C2146: syntax error : missing ';' before identifier 'PVOID'
any solution for those error? please help!!
The documentation for the function has this header requirement:
WinBase.h (include Windows.h)
This is telling you that the function is declared in WinBase.h, but that you should include Windows.h which in turn will include WinBase.h. So, you need to change your include to
#include <Windows.h>
I also wonder why you are talking about mingw considering that your compiler is MSVC. That compiler ships with a comprehensive Windows SDK. Why would you be using an SDK from mingw?

Some errors in VC++

I have a code that generates errors on my PC but does't on other PC.I have windows 7 installed and also installed the compatible SDK for windows 7.I have also included the VC directories (from Tools -> option-> vc Diretories) but still the code generates follwing errors.
error C2059: syntax error : 'constant'
error C2238: unexpected token(s) preceding ';'
error C2589: '(' : illegal token on right side of '::'
warning C4091: '' : ignored on left of 'const unsigned int' when no variable is declared
error C2143: syntax error : missing ';' before '::'
error C2059: syntax error : '::'
error C2059: syntax error : 'constant'
error C2238: unexpected token(s) preceding ';'
statement generating error are as following
static const unsigned int MAPVK_VK_TO_CHAR;
const unsigned int KeyLogger :: MAPVK_VK_TO_CHAR = 0x02;
Try selecting MAPVK_VK_TO_CHAR and hitting F12 to see if the symbol is declared elsewhere.
What's MAPVK_VK_TO_CHAR? I ask because the error might indicate that this is some macro.
Why do you make a plain identifier (not a macro) all caps, anyway? That's just begging for one of the thousands of macros in <windows.h> to trample over it. (Not that not making it all caps would prevent that, since <windows.h> sacrilegiously defines many mixed-case macros...)
Otherwise you would have to paste some minimal, compilable example showing the problem.

Ms Sitelock 1.15 and VS 2005

I'm trying to implement the MS Sitelock template into one of my Active-X Controls. I've downloaded the sitelock 1.15 sdk and I'm stuck on the very first step.
Including the sitelock.h header file causes a bunch of compile errors that have to do with the sal.h header file. It looks to me like sitelock.h wants to use attribute sal but that sal.h is only defining declspec sal. I'm using VS 2005, but the sitelock 1.5 documentation says that vs 2005 is supported. Is there something I need to do to reference attribute sal? I do have the Vista platform sdk installed. I'm including the sitelock.h in the header file of my active-x object. Perhaps that's not the place to do it?
See compile errors below:
....\public\sitelock.h(308) : error C2061: syntax error : identifier '_In_opt_count_'
..\..\public\sitelock.h(605) : see reference to class template instantiation 'CSiteLock<T>' being compiled
\public\sitelock.h(308) : error C2059: syntax error : ')'
...\public\sitelock.h(310) : error C2143: syntax error : missing ')' before '{'
...\public\sitelock.h(401) : error C2061: syntax error : identifier '_In_z_'
..\public\sitelock.h(401) : error C2059: syntax error : ')'
..\public\sitelock.h(402) : error C2143: syntax error : missing ')' before '{'
C2061: syntax error : identifier '_Inout_z_count_'
....\public\sitelock.h(451) : error C2059: syntax error : ')'
...\public\sitelock.h(452) : error C2143: syntax error : missing ')' before '{'
..\public\sitelock.h(520) : error C2061: syntax error : identifier '_In_z_'
..\public\sitelock.h(520) : error C2059: syntax error : ')'
...\public\sitelock.h(521) : error C2143: syntax error : missing ')' before '{'
...\public\sitelock.h(555) : error C2061: syntax error : identifier '_In_z_'
New SAL.H is included in the Windows server 2008 SDK, not the Vista one.
I'm still using the Vista SDK and have gotten by my compiler errors by translating the attribute sal macros to declspec sal macros in sitelock.h.
Used the notes in the following url to do the translation:
http://blogs.msdn.com/sdl/archive/2009/06/11/a-declspec-sal-to-attribute-sal-rosetta-stone.aspx